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

Commit 88208de8 authored by Henri Chataing's avatar Henri Chataing
Browse files

system/stack/btm: Migrate to libbluetooth_log

Test: m com.android.btservices
Bug: 305066880
Flag: EXEMPT, mechanical refactor
Change-Id: I6c785ac2608f80bfcd627b70263d16cc0f4f7cb0
parent 67820499
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1380,6 +1380,7 @@ cc_test {
        "test/common/mock_hcic_layer.cc",
    ],
    static_libs: [
        "libbase",
        "libbluetooth-types",
        "libbluetooth_hci_pdl",
        "libbluetooth_log",
+14 −17
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

#include <base/functional/bind.h>
#include <base/logging.h>
#include <bluetooth/log.h>

#include "btm_api.h"
#include "device/include/controller.h"
@@ -26,6 +27,8 @@
#include "stack/include/hcimsgs.h"
#include "types/raw_address.h"

using namespace bluetooth;

namespace {
BleScannerHciInterface* instance = nullptr;

@@ -55,7 +58,7 @@ static void status_handle_callback(base::Callback<void(uint8_t, uint16_t)> cb,
    handle = handle & 0x0EFF;

  } else {
    VLOG(1) << __func__ << " hci response error code: " << int{status};
    log::verbose("hci response error code: {}", int{status});
  }
  cb.Run(status, handle);
}
@@ -135,8 +138,7 @@ class BleScannerImplBase : public BleScannerHciInterface {
    uint16_t acl_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_LE);

    if (acl_handle == HCI_INVALID_HANDLE) {
      LOG(ERROR) << __func__
                 << ": Wrong mode: no LE link exist or LE not supported";
      log::error("Wrong mode: no LE link exist or LE not supported");
      return;
    }

@@ -151,8 +153,7 @@ class BleScannerImplBase : public BleScannerHciInterface {
    uint16_t acl_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_LE);

    if (acl_handle == HCI_INVALID_HANDLE) {
      LOG(ERROR) << __func__
                 << ": Wrong mode: no LE link exist or LE not supported";
      log::error("Wrong mode: no LE link exist or LE not supported");
      return;
    }

@@ -168,8 +169,7 @@ class BleScannerImplBase : public BleScannerHciInterface {
    uint16_t acl_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_LE);

    if (acl_handle == HCI_INVALID_HANDLE) {
      LOG(ERROR) << __func__
                 << ": Wrong mode: no LE link exist or LE not supported";
      log::error("Wrong mode: no LE link exist or LE not supported");
      return;
    }

@@ -246,8 +246,7 @@ class BleScannerSyncTransferImpl : public virtual BleScannerImplBase {
    uint16_t acl_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_LE);

    if (acl_handle == HCI_INVALID_HANDLE) {
      LOG(ERROR) << __func__
                 << ": Wrong mode: no LE link exist or LE not supported";
      log::error("Wrong mode: no LE link exist or LE not supported");
      return;
    }

@@ -262,8 +261,7 @@ class BleScannerSyncTransferImpl : public virtual BleScannerImplBase {
    uint16_t acl_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_LE);

    if (acl_handle == HCI_INVALID_HANDLE) {
      LOG(ERROR) << __func__
                 << ": Wrong mode: no LE link exist or LE not supported";
      log::error("Wrong mode: no LE link exist or LE not supported");
      return;
    }

@@ -279,8 +277,7 @@ class BleScannerSyncTransferImpl : public virtual BleScannerImplBase {
    uint16_t acl_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_LE);

    if (acl_handle == HCI_INVALID_HANDLE) {
      LOG(ERROR) << __func__
                 << ": Wrong mode: no LE link exist or LE not supported";
      log::error("Wrong mode: no LE link exist or LE not supported");
      return;
    }

@@ -308,16 +305,16 @@ void BleScannerHciInterface::Initialize() {
  if ((controller_get_interface()->get_ble_periodic_advertiser_list_size()) &&
      (controller_get_interface()
           ->SupportsBlePeriodicAdvertisingSyncTransferSender())) {
    LOG(INFO) << "Advertiser list in controller can be used";
    LOG(INFO) << "Periodic Adv Sync Transfer Sender role is supported";
    log::info("Advertiser list in controller can be used");
    log::info("Periodic Adv Sync Transfer Sender role is supported");
    instance = new BleScannerCompleteImpl();
  } else if (controller_get_interface()
                 ->SupportsBlePeriodicAdvertisingSyncTransferSender()) {
    LOG(INFO) << "Periodic Adv Sync Transfer Sender role is supported";
    log::info("Periodic Adv Sync Transfer Sender role is supported");
    instance = new BleScannerSyncTransferImpl();
  } else if (controller_get_interface()
                 ->get_ble_periodic_advertiser_list_size()) {
    LOG(INFO) << "Periodic Adv Sync Transfer Recipient role is supported";
    log::info("Periodic Adv Sync Transfer Recipient role is supported");
    instance = new BleScannerListImpl();
  }
  // TODO: Implement periodic adv. sync. recipient role if ever needed.
+10 −5
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@

#define LOG_TAG "ble"

#include <bluetooth/log.h>

#include <cstdint>

#include "base/functional/bind.h"
@@ -38,6 +40,8 @@
#include "stack/include/gatt_api.h"
#include "stack/include/hcimsgs.h"

using namespace bluetooth;

extern tBTM_CB btm_cb;

/*******************************************************************************
@@ -162,7 +166,7 @@ void BTM_BleReadPhy(
    const RawAddress& bd_addr,
    base::Callback<void(uint8_t tx_phy, uint8_t rx_phy, uint8_t status)> cb) {
  if (!BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE)) {
    LOG_ERROR("Wrong mode: no LE link exist or LE not supported");
    log::error("Wrong mode: no LE link exist or LE not supported");
    cb.Run(0, 0, HCI_ERR_NO_CONNECTION);
    return;
  }
@@ -170,7 +174,7 @@ void BTM_BleReadPhy(
  // checking if local controller supports it!
  if (!controller_get_interface()->SupportsBle2mPhy() &&
      !controller_get_interface()->SupportsBleCodedPhy()) {
    LOG_ERROR("request not supported in local controller!");
    log::error("request not supported in local controller!");
    cb.Run(0, 0, GATT_REQ_NOT_SUPPORTED);
    return;
  }
@@ -190,7 +194,7 @@ void doNothing(uint8_t* data, uint16_t len) {}
void BTM_BleSetPhy(const RawAddress& bd_addr, uint8_t tx_phys, uint8_t rx_phys,
                   uint16_t phy_options) {
  if (!BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE)) {
    LOG_INFO(
    log::info(
        "Unable to set phy preferences because no le acl is connected to "
        "device");
    return;
@@ -205,7 +209,8 @@ void BTM_BleSetPhy(const RawAddress& bd_addr, uint8_t tx_phys, uint8_t rx_phys,
  // checking if local controller supports it!
  if (!controller_get_interface()->SupportsBle2mPhy() &&
      !controller_get_interface()->SupportsBleCodedPhy()) {
    LOG_INFO("Local controller unable to support setting of le phy parameters");
    log::info(
        "Local controller unable to support setting of le phy parameters");
    gatt_notify_phy_updated(static_cast<tHCI_STATUS>(GATT_REQ_NOT_SUPPORTED),
                            handle, tx_phys, rx_phys);
    return;
@@ -213,7 +218,7 @@ void BTM_BleSetPhy(const RawAddress& bd_addr, uint8_t tx_phys, uint8_t rx_phys,

  if (!acl_peer_supports_ble_2m_phy(handle) &&
      !acl_peer_supports_ble_coded_phy(handle)) {
    LOG_INFO("Remote device unable to support setting of le phy parameter");
    log::info("Remote device unable to support setting of le phy parameter");
    gatt_notify_phy_updated(static_cast<tHCI_STATUS>(GATT_REQ_NOT_SUPPORTED),
                            handle, tx_phys, rx_phys);
    return;
+12 −9
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include "stack/include/btm_ble_addr.h"

#include <base/functional/bind.h>
#include <bluetooth/log.h>
#include <string.h>

#include "btm_ble_int.h"
@@ -43,6 +44,8 @@
#include "types/ble_address_with_type.h"
#include "types/raw_address.h"

using namespace bluetooth;

extern tBTM_CB btm_cb;

/* This function generates Resolvable Private Address (RPA) from Identity
@@ -76,7 +79,7 @@ static RawAddress generate_rpa_from_irk_and_rand(const Octet16& irk,
void btm_gen_resolve_paddr_low(const RawAddress& address) {
  /* when GD advertising and scanning modules are enabled, set random address
   * via address manager in GD */
  LOG_INFO("GD advertising and scanning modules are enabled, skip");
  log::info("GD advertising and scanning modules are enabled, skip");
}

/** This function generate a resolvable private address using local IRK */
@@ -205,7 +208,7 @@ static tBTM_SEC_DEV_REC* btm_find_dev_by_identity_addr(
    if (p_dev_rec->ble.identity_address_with_type.bda == bd_addr) {
      if ((p_dev_rec->ble.identity_address_with_type.type &
           (~BLE_ADDR_TYPE_ID_BIT)) != (addr_type & (~BLE_ADDR_TYPE_ID_BIT)))
        LOG_WARN("pseudo->random match with diff addr type: %d vs %d",
        log::warn("pseudo->random match with diff addr type: {} vs {}",
                  p_dev_rec->ble.identity_address_with_type.type, addr_type);

      /* found the match */
@@ -293,7 +296,7 @@ void btm_ble_refresh_peer_resolvable_private_addr(
    tBLE_RAND_ADDR_TYPE rra_type) {
  tBTM_SEC_DEV_REC* p_sec_rec = btm_find_dev(pseudo_bda);
  if (p_sec_rec == nullptr) {
    LOG_WARN("No matching known device in record");
    log::warn("No matching known device in record");
    return;
  }

@@ -316,7 +319,7 @@ void btm_ble_refresh_peer_resolvable_private_addr(
    if (!acl_refresh_remote_address(identity_address, identity_address_type,
                                    p_sec_rec->ble.pseudo_addr, rra_type,
                                    rpa)) {
      LOG_ERROR("Unknown device to refresh remote device");
      log::error("Unknown device to refresh remote device");
    }
  }
}
@@ -341,7 +344,7 @@ bool maybe_resolve_address(RawAddress* bda, tBLE_ADDR_TYPE* bda_type) {
  if (!is_in_security_db && addr_is_rpa) {
    tBTM_SEC_DEV_REC* match_rec = btm_ble_resolve_random_addr(*bda);
    if (match_rec) {
      LOG_INFO("matched/resolved random address:%s",
      log::info("matched/resolved random address:{}",
                ADDRESS_TO_LOGGABLE_CSTR(*bda));
      is_in_security_db = true;
      match_rec->ble.active_addr_type = BTM_BLE_ADDR_RRA;
@@ -354,7 +357,7 @@ bool maybe_resolve_address(RawAddress* bda, tBLE_ADDR_TYPE* bda_type) {
        *bda = match_rec->bd_addr;
      }
    } else {
      LOG_INFO("unable to match/resolve random address:%s",
      log::info("unable to match/resolve random address:{}",
                ADDRESS_TO_LOGGABLE_CSTR(*bda));
    }
  }
+15 −13
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#define LOG_TAG "bt_btm_ble"

#include <base/functional/bind.h>
#include <bluetooth/log.h>

#include "btm_ble_api.h"
#include "os/log.h"
@@ -32,6 +33,7 @@

extern tBTM_CB btm_cb;

using namespace bluetooth;
using base::Bind;
using bluetooth::Uuid;

@@ -125,7 +127,7 @@ static uint8_t btm_ble_ocf_to_condtype(uint8_t ocf) {
static void btm_flt_update_cb(uint8_t expected_ocf, tBTM_BLE_PF_CFG_CBACK cb,
                              uint8_t* p, uint16_t evt_len) {
  if (evt_len != 4) {
    LOG_ERROR("%s: bad length: %d", __func__, evt_len);
    log::error("bad length: {}", evt_len);
    return;
  }

@@ -136,8 +138,8 @@ static void btm_flt_update_cb(uint8_t expected_ocf, tBTM_BLE_PF_CFG_CBACK cb,
  STREAM_TO_UINT8(num_avail, p);

  if (expected_ocf != op_subcode) {
    LOG_ERROR("%s: Incorrect opcode: 0x%02x, expected: 0x%02x", __func__,
              expected_ocf, op_subcode);
    log::error("Incorrect opcode: 0x{:02x}, expected: 0x{:02x}", expected_ocf,
               op_subcode);
    return;
  }

@@ -149,8 +151,8 @@ static void btm_flt_update_cb(uint8_t expected_ocf, tBTM_BLE_PF_CFG_CBACK cb,
  }

  uint8_t cond_type = btm_ble_ocf_to_condtype(expected_ocf);
  LOG_VERBOSE("%s: Recd: %d, %d, %d, %d, %d", __func__, op_subcode,
              expected_ocf, action, status, num_avail);
  log::verbose("Recd: {}, {}, {}, {}, {}", op_subcode, expected_ocf, action,
               status, num_avail);
  if (HCI_SUCCESS == status) {
    if (btm_ble_adv_filt_cb.cur_filter_target.bda.IsEmpty())
      btm_ble_cs_update_pf_counter(static_cast<tBTM_BLE_SCAN_COND_OP>(action),
@@ -269,7 +271,7 @@ static uint8_t btm_ble_cs_update_pf_counter(tBTM_BLE_SCAN_COND_OP action,
  uint8_t* p_counter = NULL;

  if (cond_type > BTM_BLE_PF_TYPE_ALL) {
    LOG_ERROR("unknown PF filter condition type %d", cond_type);
    log::error("unknown PF filter condition type {}", cond_type);
    return BTM_BLE_INVALID_COUNTER;
  }

@@ -300,13 +302,13 @@ static uint8_t btm_ble_cs_update_pf_counter(tBTM_BLE_SCAN_COND_OP action,
      p_counter = p_addr_filter->pf_counter;
      if (num_available > 0) p_counter[cond_type] += 1;

      LOG_VERBOSE("counter = %d, maxfilt = %d, num_avbl=%d",
      log::verbose("counter = {}, maxfilt = {}, num_avbl={}",
                   p_counter[cond_type], cmn_ble_vsc_cb.max_filter,
                   num_available);
      return p_counter[cond_type];
    }
  } else {
    LOG_ERROR("no matching filter counter found");
    log::error("no matching filter counter found");
  }
  /* no matching filter located and updated */
  return BTM_BLE_INVALID_COUNTER;
@@ -341,17 +343,17 @@ void BTM_BleAdvFilterParamSetup(

  p = param;
  memset(param, 0, len);
  LOG_VERBOSE("%s", __func__);
  log::verbose("");

  if (BTM_BLE_SCAN_COND_ADD == action) {
    p_bda_filter = btm_ble_find_addr_filter_counter(nullptr);
    if (NULL == p_bda_filter) {
      LOG_ERROR("BD Address not found!");
      log::error("BD Address not found!");
      cb.Run(0, BTM_BLE_PF_ENABLE, btm_status_value(BTM_UNKNOWN_ADDR));
      return;
    }

    LOG_VERBOSE("%s : Feat mask:%d", __func__, p_filt_params->feat_seln);
    log::verbose("Feat mask:{}", p_filt_params->feat_seln);
    /* select feature based on control block settings */
    UINT8_TO_STREAM(p, BTM_BLE_META_PF_FEAT_SEL);
    UINT8_TO_STREAM(p, BTM_BLE_SCAN_COND_ADD);
Loading