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

Commit b25d02f4 authored by Chris Manton's avatar Chris Manton Committed by Gerrit Code Review
Browse files

Merge changes Ic583e487,Ic589759c,Ibe9720b5,I3fc83d6d,I3cccdf77, ...

* changes:
  shim: Move disconnect classic/le into thread safe space
  shim: Add acl tests
  shim: Replace mock do_in_main_thread with a fake
  shim: Move dumpsys map off heap into static allocation
  shim: Clean up mock entry and add common header inclusion
  gd: Make address protected to set it for tests
  Untangle HCI_STATUS/BTM_STATUS bta/dm/bta_dm_act
  Enum-ify tSMP_STATUS
parents 565ab0ea 928c9504
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ void BTA_dm_update_policy(tBTA_SYS_CONN_STATUS status, uint8_t id,
                          uint8_t app_id, const RawAddress& peer_addr);

/* Extended Inquiry Response */
static uint8_t bta_dm_sp_cback(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data);
static tBTM_STATUS bta_dm_sp_cback(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data);

static void bta_dm_set_eir(char* local_name);

@@ -113,7 +113,7 @@ static void bta_dm_cancel_gatt_discovery(const RawAddress& bd_addr);
static void bta_dm_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data);
extern tBTA_DM_CONTRL_STATE bta_dm_pm_obtain_controller_state(void);
#if (BLE_VND_INCLUDED == TRUE)
static void bta_dm_ctrl_features_rd_cmpl_cback(tBTM_STATUS result);
static void bta_dm_ctrl_features_rd_cmpl_cback(tHCI_STATUS result);
#endif

#ifndef BTA_DM_BLE_ADV_CHNL_MAP
@@ -2108,7 +2108,8 @@ static void bta_dm_authentication_complete_cback(
 * Returns          void
 *
 ******************************************************************************/
static uint8_t bta_dm_sp_cback(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data) {
static tBTM_STATUS bta_dm_sp_cback(tBTM_SP_EVT event,
                                   tBTM_SP_EVT_DATA* p_data) {
  tBTM_STATUS status = BTM_CMD_STARTED;
  tBTA_DM_SEC sec_event;
  tBTA_DM_SEC_EVT pin_evt = BTA_DM_SP_KEY_NOTIF_EVT;
@@ -3674,8 +3675,8 @@ static void bta_ble_energy_info_cmpl(tBTM_BLE_TX_TIME_MS tx_time,
                                     tBTM_BLE_RX_TIME_MS rx_time,
                                     tBTM_BLE_IDLE_TIME_MS idle_time,
                                     tBTM_BLE_ENERGY_USED energy_used,
                                     tBTM_STATUS status) {
  tBTA_STATUS st = (status == BTM_SUCCESS) ? BTA_SUCCESS : BTA_FAILURE;
                                     tHCI_STATUS status) {
  tBTA_STATUS st = (status == HCI_SUCCESS) ? BTA_SUCCESS : BTA_FAILURE;
  tBTA_DM_CONTRL_STATE ctrl_state = 0;

  if (BTA_SUCCESS == st) ctrl_state = bta_dm_pm_obtain_controller_state();
@@ -3690,8 +3691,8 @@ void bta_dm_ble_get_energy_info(
    tBTA_BLE_ENERGY_INFO_CBACK* p_energy_info_cback) {
  bta_dm_cb.p_energy_info_cback = p_energy_info_cback;
  tBTM_STATUS btm_status = BTM_BleGetEnergyInfo(bta_ble_energy_info_cmpl);
  if (BTM_CMD_STARTED != btm_status)
    bta_ble_energy_info_cmpl(0, 0, 0, 0, btm_status);
  if (btm_status != BTM_CMD_STARTED)
    bta_ble_energy_info_cmpl(0, 0, 0, 0, HCI_ERR_UNSPECIFIED);
}

#ifndef BTA_DM_GATT_CLOSE_DELAY_TOUT
@@ -3902,9 +3903,9 @@ static void bta_dm_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) {
 * Parameters:
 *
 ******************************************************************************/
static void bta_dm_ctrl_features_rd_cmpl_cback(tBTM_STATUS result) {
static void bta_dm_ctrl_features_rd_cmpl_cback(tHCI_STATUS result) {
  APPL_TRACE_DEBUG("%s  status = %d ", __func__, result);
  if (result == BTM_SUCCESS) {
  if (result == HCI_SUCCESS) {
    if (bta_dm_cb.p_sec_cback)
      bta_dm_cb.p_sec_cback(BTA_DM_LE_FEATURES_READ, NULL);
  } else {
+4 −0
Original line number Diff line number Diff line
@@ -76,7 +76,11 @@ class ClassicAclConnection : public AclConnection {

 private:
  AclConnectionInterface* acl_connection_interface_;

 protected:
  Address address_;

 private:
  struct impl;
  struct impl* pimpl_ = nullptr;
  DISALLOW_COPY_AND_ASSIGN(ClassicAclConnection);
+1 −1
Original line number Diff line number Diff line
@@ -233,6 +233,7 @@ cc_test {
        "shim/metrics_api.cc",
        "shim/shim.cc",
        "shim/stack.cc",
        "test/common/main_handler.cc",
        "test/common/mock_acl_ble.cc",
        "test/common/mock_acl_btm_pm.cc",
        "test/common/mock_bta_dm_act.cc",
@@ -243,7 +244,6 @@ cc_test {
        "test/common/mock_btm_inq.cc",
        "test/common/mock_btm_main.cc",
        "test/common/mock_btm_sec.cc",
        "test/common/mock_btu_task.cc",
        "test/common/mock_entry.cc",
        "test/common/mock_gatt_main.cc",
        "test/common/mock_hcic_hcicmds.cc",
+38 −28
Original line number Diff line number Diff line
@@ -763,6 +763,40 @@ struct shim::legacy::Acl::impl {
    handle_to_classic_connection_map_[handle]->SetConnectionEncryption(enable);
  }

  void disconnect_classic(uint16_t handle, tHCI_STATUS reason) {
    auto connection = handle_to_classic_connection_map_.find(handle);
    if (connection != handle_to_classic_connection_map_.end()) {
      auto remote_address = connection->second->GetRemoteAddress();
      connection->second->InitiateDisconnect(
          ToDisconnectReasonFromLegacy(reason));
      LOG_DEBUG("Disconnection initiated classic remote:%s handle:%hu",
                PRIVATE_ADDRESS(remote_address), handle);
      BTM_LogHistory(kBtmLogTag, ToRawAddress(remote_address),
                     "Disconnection initiated", "classic");
    } else {
      LOG_WARN("Unable to disconnect unknown classic connection handle:0x%04x",
               handle);
    }
  }

  void disconnect_le(uint16_t handle, tHCI_STATUS reason) {
    auto connection = handle_to_le_connection_map_.find(handle);
    if (connection != handle_to_le_connection_map_.end()) {
      auto remote_address_with_type =
          connection->second->GetRemoteAddressWithType();
      connection->second->InitiateDisconnect(
          ToDisconnectReasonFromLegacy(reason));
      LOG_DEBUG("Disconnection initiated le remote:%s handle:%hu",
                PRIVATE_ADDRESS(remote_address_with_type), handle);
      BTM_LogHistory(kBtmLogTag,
                     ToLegacyAddressWithType(remote_address_with_type),
                     "Disconnection initiated", "Le");
    } else {
      LOG_WARN("Unable to disconnect unknown le connection handle:0x%04x",
               handle);
    }
  }

  void accept_le_connection_from(const hci::AddressWithType& address_with_type,
                                 std::promise<bool> promise) {
    if (shadow_acceptlist_.IsFull()) {
@@ -1285,38 +1319,14 @@ void shim::legacy::Acl::ConfigureLePrivacy(bool is_le_privacy_enabled) {
}

void shim::legacy::Acl::DisconnectClassic(uint16_t handle, tHCI_STATUS reason) {
  auto connection = pimpl_->handle_to_classic_connection_map_.find(handle);
  if (connection != pimpl_->handle_to_classic_connection_map_.end()) {
    auto remote_address = connection->second->GetRemoteAddress();
    connection->second->InitiateDisconnect(
        ToDisconnectReasonFromLegacy(reason));
    LOG_DEBUG("Disconnection initiated classic remote:%s handle:%hu",
              PRIVATE_ADDRESS(remote_address), handle);
    BTM_LogHistory(kBtmLogTag, ToRawAddress(remote_address),
                   "Disconnection initiated", "classic");
  } else {
    LOG_WARN("Unable to disconnect unknown classic connection handle:0x%04x",
             handle);
  }
  handler_->CallOn(pimpl_.get(), &Acl::impl::disconnect_classic, handle,
                   reason);
}

void shim::legacy::Acl::DisconnectLe(uint16_t handle, tHCI_STATUS reason) {
  auto connection = pimpl_->handle_to_le_connection_map_.find(handle);
  if (connection != pimpl_->handle_to_le_connection_map_.end()) {
    auto remote_address_with_type =
        connection->second->GetRemoteAddressWithType();
    connection->second->InitiateDisconnect(
        ToDisconnectReasonFromLegacy(reason));
    LOG_DEBUG("Disconnection initiated le remote:%s handle:%hu",
              PRIVATE_ADDRESS(remote_address_with_type), handle);
    BTM_LogHistory(kBtmLogTag,
                   ToLegacyAddressWithType(remote_address_with_type),
                   "Disconnection initiated", "Le");
  } else {
    LOG_WARN("Unable to disconnect unknown le connection handle:0x%04x",
             handle);
  }
  handler_->CallOn(pimpl_.get(), &Acl::impl::disconnect_le, handle, reason);
}

bool shim::legacy::Acl::HoldMode(uint16_t hci_handle, uint16_t max_interval,
                                 uint16_t min_interval) {
  handler_->CallOn(pimpl_.get(), &Acl::impl::HoldMode, hci_handle, max_interval,
+11 −11
Original line number Diff line number Diff line
@@ -23,31 +23,31 @@
#include "shim/dumpsys.h"

namespace {

constexpr char kModuleName[] = "shim::legacy::dumpsys";
static std::unordered_map<const void*, bluetooth::shim::DumpsysFunction>*
    dumpsys_functions_{nullptr};
static std::unordered_map<const void*, bluetooth::shim::DumpsysFunction>
    dumpsys_functions_;

}  // namespace

void bluetooth::shim::RegisterDumpsysFunction(const void* token,
                                              DumpsysFunction func) {
  dumpsys_functions_ =
      new std::unordered_map<const void*, bluetooth::shim::DumpsysFunction>();
  CHECK(dumpsys_functions_->find(token) == dumpsys_functions_->end());
  dumpsys_functions_->insert({token, func});
  CHECK(dumpsys_functions_.find(token) == dumpsys_functions_.end());
  dumpsys_functions_.insert({token, func});
}

void bluetooth::shim::UnregisterDumpsysFunction(const void* token) {
  CHECK(dumpsys_functions_->find(token) != dumpsys_functions_->end());
  dumpsys_functions_->erase(token);
  CHECK(dumpsys_functions_.find(token) != dumpsys_functions_.end());
  dumpsys_functions_.erase(token);
}

void bluetooth::shim::Dump(int fd, const char** args) {
  if (dumpsys_functions_ == nullptr) {
  if (dumpsys_functions_.empty()) {
    dprintf(fd, "%s No registered dumpsys shim legacy targets\n", kModuleName);
  } else {
    dprintf(fd, "%s Dumping shim legacy targets:%zd\n", kModuleName,
            dumpsys_functions_->size());
    for (auto& dumpsys : *dumpsys_functions_) {
            dumpsys_functions_.size());
    for (auto& dumpsys : dumpsys_functions_) {
      dumpsys.second(fd);
    }
  }
Loading