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

Commit 18935294 authored by Henri Chataing's avatar Henri Chataing Committed by Gerrit Code Review
Browse files

Merge changes Ia01c229d,I6dd97f7a,I35057c30 into main

* changes:
  system/stack/hid: Migrate to libbluetooth_log
  system/stack/gatt: Migrate to libbluetooth_log
  system/stack/gap: Migrate to libbluetooth_log
parents 1f532b67 5bbc7ee2
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -128,4 +128,14 @@ struct MsftAdvMonitor {
  std::vector<MsftAdvMonitorPattern> patterns;
};

#if __has_include(<bluetooth/log.h>)
#include <bluetooth/log.h>

namespace fmt {
template <>
struct formatter<bt_gatt_db_attribute_type_t>
    : enum_formatter<bt_gatt_db_attribute_type_t> {};
}  // namespace fmt
#endif  // __has_include(<bluetooth/log.h>)

#endif /* ANDROID_INCLUDE_BT_COMMON_TYPES_H */
+5 −0
Original line number Diff line number Diff line
@@ -971,6 +971,7 @@ cc_test {
        "libcutils",
    ],
    static_libs: [
        "libbase",
        "libbluetooth-types",
        "libbluetooth_gd",
        "libbluetooth_log",
@@ -1024,6 +1025,7 @@ cc_test {
        "libcutils",
    ],
    static_libs: [
        "libbase",
        "libbluetooth-types",
        "libbluetooth_crypto_toolbox",
        "libbluetooth_gd",
@@ -1326,6 +1328,7 @@ cc_test {
        "libcutils",
    ],
    static_libs: [
        "libbase",
        "libbluetooth-types",
        "libbluetooth_crypto_toolbox",
        "libbluetooth_gd",
@@ -1693,6 +1696,7 @@ cc_test {
        "test/hid/stack_hid_test.cc",
    ],
    static_libs: [
        "libbase",
        "libbluetooth-types",
        "libbluetooth_crypto_toolbox",
        "libbluetooth_log",
@@ -1858,6 +1862,7 @@ cc_test {
    ],
    static_libs: [
        "bluetooth_flags_c_lib",
        "libbase",
        "libbluetooth-types",
        "libbluetooth_crypto_toolbox",
        "libbluetooth_gd",
+12 −13
Original line number Diff line number Diff line
@@ -16,8 +16,7 @@
 *
 ******************************************************************************/

#include <base/logging.h>
#include <base/strings/stringprintf.h>
#include <bluetooth/log.h>
#include <string.h>

#include <array>
@@ -34,8 +33,8 @@
#include "types/bt_transport.h"
#include "types/raw_address.h"

using base::StringPrintf;
using bluetooth::Uuid;
using namespace bluetooth;

namespace {

@@ -222,17 +221,16 @@ void server_attr_request_cback(uint16_t conn_id, uint32_t trans_id,

    case GATTS_REQ_TYPE_WRITE_EXEC:
      ignore = true;
      VLOG(1) << "Ignore GATTS_REQ_TYPE_WRITE_EXEC";
      log::verbose("Ignore GATTS_REQ_TYPE_WRITE_EXEC");
      break;

    case GATTS_REQ_TYPE_MTU:
      VLOG(1) << "Get MTU exchange new mtu size: " << +p_data->mtu;
      log::verbose("Get MTU exchange new mtu size: {}", +p_data->mtu);
      ignore = true;
      break;

    default:
      VLOG(1) << StringPrintf("Unknown/unexpected LE GAP ATT request: 0x%02x",
                              type);
      log::verbose("Unknown/unexpected LE GAP ATT request: 0x{:02x}", type);
      break;
  }

@@ -295,19 +293,20 @@ void client_connect_cback(tGATT_IF, const RawAddress& bda, uint16_t conn_id,
                          tBT_TRANSPORT) {
  tGAP_CLCB* p_clcb = find_clcb_by_bd_addr(bda);
  if (p_clcb == NULL) {
    LOG_INFO("No active GAP service found for peer:%s callback:%s",
             ADDRESS_TO_LOGGABLE_CSTR(bda), (connected) ? "Connected" : "Disconnected");
    log::info("No active GAP service found for peer:{} callback:{}",
              ADDRESS_TO_LOGGABLE_CSTR(bda),
              (connected) ? "Connected" : "Disconnected");
    return;
  }

  if (connected) {
    LOG_DEBUG("Connected GAP to remote device");
    log::debug("Connected GAP to remote device");
    p_clcb->conn_id = conn_id;
    p_clcb->connected = true;
    /* start operation is pending */
    send_cl_read_request(*p_clcb);
  } else {
    LOG_WARN("Disconnected GAP from remote device");
    log::warn("Disconnected GAP from remote device");
    p_clcb->connected = false;
    cl_op_cmpl(*p_clcb, false, 0, NULL);
    /* clean up clcb */
@@ -545,13 +544,13 @@ bool GAP_BleCancelReadPeerDevName(const RawAddress& peer_bda) {
  tGAP_CLCB* p_clcb = find_clcb_by_bd_addr(peer_bda);

  if (p_clcb == NULL) {
    LOG(ERROR) << "Cannot cancel current op is not get dev name";
    log::error("Cannot cancel current op is not get dev name");
    return false;
  }

  if (!p_clcb->connected) {
    if (!GATT_CancelConnect(gatt_if, peer_bda, true)) {
      LOG(ERROR) << "Cannot cancel where No connection id";
      log::error("Cannot cancel where No connection id");
      return false;
    }
  }
+13 −18
Original line number Diff line number Diff line
@@ -16,8 +16,7 @@
 *
 ******************************************************************************/

#include <base/logging.h>
#include <base/strings/stringprintf.h>
#include <bluetooth/log.h>
#include <string.h>

#include "device/include/controller.h"
@@ -32,7 +31,7 @@
#include "stack/include/bt_hdr.h"
#include "types/raw_address.h"

using base::StringPrintf;
using namespace bluetooth;

/* Define the GAP Connection Control Block */
typedef struct {
@@ -197,8 +196,8 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id,
  /* A client MUST have specified a bd addr to connect with */
  if (!p_ccb->rem_addr_specified && !is_server) {
    gap_release_ccb(p_ccb);
    LOG(ERROR)
        << "GAP ERROR: Client must specify a remote BD ADDR to connect to!";
    log::error(
        "GAP ERROR: Client must specify a remote BD ADDR to connect to!");
    return (GAP_INVALID_HANDLE);
  }

@@ -212,7 +211,7 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id,

    uint16_t max_mps = controller_get_interface()->get_acl_data_size_ble();
    if (le_mps > max_mps) {
      LOG(INFO) << "Limiting MPS to one buffer size - " << max_mps;
      log::info("Limiting MPS to one buffer size - {}", max_mps);
      le_mps = max_mps;
    }
    p_ccb->local_coc_cfg.mps = le_mps;
@@ -241,8 +240,7 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id,
        L2CA_Register2(psm, conn.reg_info, false /* enable_snoop */,
                       &p_ccb->ertm_info, L2CAP_SDU_LENGTH_MAX, 0, security);
    if (p_ccb->psm == 0) {
      LOG(ERROR) << StringPrintf("%s: Failure registering PSM 0x%04x", __func__,
                                 psm);
      log::error("Failure registering PSM 0x{:04x}", psm);
      gap_release_ccb(p_ccb);
      return (GAP_INVALID_HANDLE);
    }
@@ -252,8 +250,7 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id,
    p_ccb->psm =
        L2CA_RegisterLECoc(psm, conn.reg_info, security, p_ccb->local_coc_cfg);
    if (p_ccb->psm == 0) {
      LOG(ERROR) << StringPrintf("%s: Failure registering PSM 0x%04x", __func__,
                                 psm);
      log::error("Failure registering PSM 0x{:04x}", psm);
      gap_release_ccb(p_ccb);
      return (GAP_INVALID_HANDLE);
    }
@@ -593,10 +590,10 @@ static void gap_connect_ind(const RawAddress& bd_addr, uint16_t l2cap_cid,
  }

  if (xx == GAP_MAX_CONNECTIONS) {
    LOG(WARNING) << "*******";
    LOG(WARNING) << "WARNING: GAP Conn Indication for Unexpected Bd "
                    "Addr...Disconnecting";
    LOG(WARNING) << "*******";
    log::warn("*******");
    log::warn(
        "WARNING: GAP Conn Indication for Unexpected Bd Addr...Disconnecting");
    log::warn("*******");

    /* Disconnect because it is an unexpected connection */
    if (BTM_UseLeLink(bd_addr)) {
@@ -829,10 +826,8 @@ static void gap_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg) {
    fixed_queue_enqueue(p_ccb->rx_queue, p_msg);

    p_ccb->rx_queue_size += p_msg->len;
    /*
    VLOG(1) << StringPrintf ("gap_data_ind - rx_queue_size=%d, msg len=%d",
                                   p_ccb->rx_queue_size, p_msg->len);
     */
    // log::verbose("gap_data_ind - rx_queue_size={}, msg len={}",
    //              p_ccb->rx_queue_size, p_msg->len);

    p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_CONN_DATA_AVAIL, nullptr);
  } else {
+41 −38
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
 ******************************************************************************/

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

#include "gatt_int.h"
#include "internal_include/bt_target.h"
@@ -39,6 +40,8 @@

using base::StringPrintf;
using bluetooth::Uuid;
using namespace bluetooth;

/**********************************************************************
 *   ATT protocl message building utility                              *
 **********************************************************************/
@@ -312,8 +315,7 @@ static BT_HDR* attp_build_value_cmd(uint16_t payload_size, uint8_t op_code,
      /* update handle value pair length */
      if (op_code == GATT_RSP_READ_BY_TYPE) *p_pair_len = (len + 2);

      LOG(WARNING) << StringPrintf(
          "attribute value too long, to be truncated to %d", len);
      log::warn("attribute value too long, to be truncated to {}", len);
    }

    ARRAY_TO_STREAM(p, p_data, len);
@@ -335,18 +337,18 @@ tGATT_STATUS attp_send_msg_to_l2cap(tGATT_TCB& tcb, uint16_t lcid,
  uint16_t l2cap_ret;

  if (lcid == L2CAP_ATT_CID) {
    LOG_DEBUG("Sending ATT message on att fixed channel");
    log::debug("Sending ATT message on att fixed channel");
    l2cap_ret = L2CA_SendFixedChnlData(lcid, tcb.peer_bda, p_toL2CAP);
  } else {
    LOG_DEBUG("Sending ATT message on lcid:%hu", lcid);
    log::debug("Sending ATT message on lcid:{}", lcid);
    l2cap_ret = (uint16_t)L2CA_DataWrite(lcid, p_toL2CAP);
  }

  if (l2cap_ret == L2CAP_DW_FAILED) {
    LOG(ERROR) << __func__ << ": failed to write data to L2CAP";
    log::error("failed to write data to L2CAP");
    return GATT_INTERNAL_ERROR;
  } else if (l2cap_ret == L2CAP_DW_CONGESTED) {
    VLOG(1) << StringPrintf("ATT congested, message accepted");
    log::verbose("ATT congested, message accepted");
    return GATT_CONGESTED;
  }
  return GATT_SUCCESS;
@@ -358,7 +360,8 @@ BT_HDR* attp_build_sr_msg(tGATT_TCB& tcb, uint8_t op_code, tGATT_SR_MSG* p_msg,
  uint16_t offset = 0;

  if (payload_size == 0) {
    LOG_ERROR("Cannot send response (op: 0x%02x) due to payload size = 0, %s",
    log::error(
        "Cannot send response (op: 0x{:02x}) due to payload size = 0, {}",
        op_code, ADDRESS_TO_LOGGABLE_CSTR(tcb.peer_bda));
    return nullptr;
  }
@@ -366,8 +369,8 @@ BT_HDR* attp_build_sr_msg(tGATT_TCB& tcb, uint8_t op_code, tGATT_SR_MSG* p_msg,
  switch (op_code) {
    case GATT_RSP_READ_BLOB:
    case GATT_RSP_PREPARE_WRITE:
      VLOG(1) << StringPrintf(
          "ATT_RSP_READ_BLOB/GATT_RSP_PREPARE_WRITE: len = %d offset = %d",
      log::verbose(
          "ATT_RSP_READ_BLOB/GATT_RSP_PREPARE_WRITE: len = {} offset = {}",
          p_msg->attr_value.len, p_msg->attr_value.offset);
      offset = p_msg->attr_value.offset;
      FALLTHROUGH_INTENDED; /* FALLTHROUGH */
@@ -393,7 +396,7 @@ BT_HDR* attp_build_sr_msg(tGATT_TCB& tcb, uint8_t op_code, tGATT_SR_MSG* p_msg,
      return attp_build_mtu_cmd(op_code, p_msg->mtu);

    default:
      LOG(FATAL) << "attp_build_sr_msg: unknown op code = " << +op_code;
      log::fatal("attp_build_sr_msg: unknown op code = {}", +op_code);
      return nullptr;
  }
}
@@ -414,11 +417,11 @@ BT_HDR* attp_build_sr_msg(tGATT_TCB& tcb, uint8_t op_code, tGATT_SR_MSG* p_msg,
 ******************************************************************************/
tGATT_STATUS attp_send_sr_msg(tGATT_TCB& tcb, uint16_t cid, BT_HDR* p_msg) {
  if (p_msg == NULL) {
    LOG_WARN("Unable to send empty message");
    log::warn("Unable to send empty message");
    return GATT_NO_RESOURCES;
  }

  LOG_DEBUG("Sending server response or indication message to client");
  log::debug("Sending server response or indication message to client");
  p_msg->offset = L2CAP_MIN_OFFSET;
  return attp_send_msg_to_l2cap(tcb, cid, p_msg);
}
@@ -442,24 +445,24 @@ static tGATT_STATUS attp_cl_send_cmd(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
  if (gatt_tcb_is_cid_busy(tcb, p_clcb->cid) &&
      cmd_code != GATT_HANDLE_VALUE_CONF) {
    if (gatt_cmd_enq(tcb, p_clcb, true, cmd_code, p_cmd)) {
      LOG_DEBUG("Enqueued ATT command %p conn_id=0x%04x, cid=%d", p_clcb,
                p_clcb->conn_id, p_clcb->cid);
      log::debug("Enqueued ATT command {} conn_id=0x{:04x}, cid={}",
                 fmt::ptr(p_clcb), p_clcb->conn_id, p_clcb->cid);
      return GATT_CMD_STARTED;
    }

    LOG_ERROR("%s, cid 0x%02x already disconnected",
    log::error("{}, cid 0x{:02x} already disconnected",
               ADDRESS_TO_LOGGABLE_CSTR(tcb.peer_bda), p_clcb->cid);
    return GATT_INTERNAL_ERROR;
  }

  LOG_DEBUG(
      "Sending ATT command to l2cap cid:0x%04x eatt_channels:%u transport:%s",
      p_clcb->cid, tcb.eatt, bt_transport_text(tcb.transport).c_str());
  log::debug(
      "Sending ATT command to l2cap cid:0x{:04x} eatt_channels:{} transport:{}",
      p_clcb->cid, tcb.eatt, bt_transport_text(tcb.transport));
  tGATT_STATUS att_ret = attp_send_msg_to_l2cap(tcb, p_clcb->cid, p_cmd);
  if (att_ret != GATT_CONGESTED && att_ret != GATT_SUCCESS) {
    LOG_WARN(
        "Unable to send ATT command to l2cap layer %p conn_id=0x%04x, cid=%d",
        p_clcb, p_clcb->conn_id, p_clcb->cid);
    log::warn(
        "Unable to send ATT command to l2cap layer {} conn_id=0x{:04x}, cid={}",
        fmt::ptr(p_clcb), p_clcb->conn_id, p_clcb->cid);
    return GATT_INTERNAL_ERROR;
  }

@@ -467,11 +470,12 @@ static tGATT_STATUS attp_cl_send_cmd(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
    return att_ret;
  }

  LOG_DEBUG("Starting ATT response timer %p conn_id=0x%04x, cid=%d", p_clcb,
            p_clcb->conn_id, p_clcb->cid);
  log::debug("Starting ATT response timer {} conn_id=0x{:04x}, cid={}",
             fmt::ptr(p_clcb), p_clcb->conn_id, p_clcb->cid);
  gatt_start_rsp_timer(p_clcb);
  if (!gatt_cmd_enq(tcb, p_clcb, false, cmd_code, NULL)) {
    LOG_ERROR("Could not queue sent request. %s, cid 0x%02x already disconnected",
    log::error(
        "Could not queue sent request. {}, cid 0x{:02x} already disconnected",
        ADDRESS_TO_LOGGABLE_CSTR(tcb.peer_bda), p_clcb->cid);
    return GATT_INTERNAL_ERROR;
  }
@@ -530,13 +534,13 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
  uint16_t offset = 0, handle;

  if (!p_clcb) {
    LOG_ERROR("Missing p_clcb");
    log::error("Missing p_clcb");
    return GATT_ILLEGAL_PARAMETER;
  }

  uint16_t payload_size = gatt_tcb_get_payload_size(tcb, p_clcb->cid);
  if (payload_size == 0) {
    LOG_ERROR("Cannot send request (op: 0x%02x) due to payload size = 0, %s",
    log::error("Cannot send request (op: 0x{:02x}) due to payload size = 0, {}",
               op_code, ADDRESS_TO_LOGGABLE_CSTR(tcb.peer_bda));
    return GATT_NO_RESOURCES;
  }
@@ -544,8 +548,8 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
  switch (op_code) {
    case GATT_REQ_MTU:
      if (p_msg->mtu > GATT_MAX_MTU_SIZE) {
        LOG_WARN(
            "GATT message MTU is larger than max GATT MTU size op_code:%hhu",
        log::warn(
            "GATT message MTU is larger than max GATT MTU size op_code:{}",
            op_code);
        return GATT_ILLEGAL_PARAMETER;
      }
@@ -558,7 +562,7 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
      if (!GATT_HANDLE_IS_VALID(p_msg->browse.s_handle) ||
          !GATT_HANDLE_IS_VALID(p_msg->browse.e_handle) ||
          p_msg->browse.s_handle > p_msg->browse.e_handle) {
        LOG_WARN("GATT message has invalid handle op_code:%hhu", op_code);
        log::warn("GATT message has invalid handle op_code:{}", op_code);
        return GATT_ILLEGAL_PARAMETER;
      }

@@ -574,7 +578,7 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
          (op_code == GATT_REQ_READ) ? p_msg->handle : p_msg->read_blob.handle;
      /*  handle checking */
      if (!GATT_HANDLE_IS_VALID(handle)) {
        LOG_WARN("GATT message has invalid handle op_code:%hhu", op_code);
        log::warn("GATT message has invalid handle op_code:{}", op_code);
        return GATT_ILLEGAL_PARAMETER;
      }

@@ -588,7 +592,7 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
    case GATT_CMD_WRITE:
    case GATT_SIGN_CMD_WRITE:
      if (!GATT_HANDLE_IS_VALID(p_msg->attr_value.handle)) {
        LOG_WARN("GATT message has invalid handle op_code:%hhu", op_code);
        log::warn("GATT message has invalid handle op_code:{}", op_code);
        return GATT_ILLEGAL_PARAMETER;
      }

@@ -618,9 +622,8 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
  }

  if (p_cmd == NULL) {
    LOG_WARN(
        "Unable to build proper GATT message to send to peer device "
        "op_code:%hhu",
    log::warn(
        "Unable to build proper GATT message to send to peer device op_code:{}",
        op_code);
    return GATT_NO_RESOURCES;
  }
Loading