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

Commit ed7bae9d authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Get rid of GAP_TRACE_* logs

This is a step required for making GAP testable, and not dependent on
any global log structures.

Change-Id: I5073e800cf842864021328308feb59a409927b2b
parent a17619d7
Loading
Loading
Loading
Loading
+0 −27
Original line number Diff line number Diff line
@@ -55,7 +55,6 @@ static const char BTE_LOGMSG_MODULE[] = "bte_logmsg_module";
#define BTTRC_ID_STK_CTP 26
#define BTTRC_ID_STK_FTC 27
#define BTTRC_ID_STK_FTS 28
#define BTTRC_ID_STK_GAP 29
#define BTTRC_ID_STK_HCRP 31
#define BTTRC_ID_STK_ICP 32
#define BTTRC_ID_STK_OPC 33
@@ -159,10 +158,6 @@ static const char BTE_LOGMSG_MODULE[] = "bte_logmsg_module";
#define SDP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif

#ifndef GAP_INITIAL_TRACE_LEVEL
#define GAP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif

#ifndef BNEP_INITIAL_TRACE_LEVEL
#define BNEP_INITIAL_TRACE_LEVEL BT_TRACE_LEVEL_WARNING
#endif
@@ -340,28 +335,6 @@ static const char BTE_LOGMSG_MODULE[] = "bte_logmsg_module";
      BT_TRACE(TRACE_LAYER_RFCOMM, TRACE_TYPE_DEBUG, ##__VA_ARGS__); \
  }

/* Generic Access Profile traces */
#define GAP_TRACE_ERROR(...)                                      \
  {                                                               \
    if (gap_cb.trace_level >= BT_TRACE_LEVEL_ERROR)               \
      BT_TRACE(TRACE_LAYER_GAP, TRACE_TYPE_ERROR, ##__VA_ARGS__); \
  }
#define GAP_TRACE_EVENT(...)                                      \
  {                                                               \
    if (gap_cb.trace_level >= BT_TRACE_LEVEL_EVENT)               \
      BT_TRACE(TRACE_LAYER_GAP, TRACE_TYPE_EVENT, ##__VA_ARGS__); \
  }
#define GAP_TRACE_API(...)                                      \
  {                                                             \
    if (gap_cb.trace_level >= BT_TRACE_LEVEL_API)               \
      BT_TRACE(TRACE_LAYER_GAP, TRACE_TYPE_API, ##__VA_ARGS__); \
  }
#define GAP_TRACE_WARNING(...)                                      \
  {                                                                 \
    if (gap_cb.trace_level >= BT_TRACE_LEVEL_WARNING)               \
      BT_TRACE(TRACE_LAYER_GAP, TRACE_TYPE_WARNING, ##__VA_ARGS__); \
  }

/* define traces for HID Host */
#define HIDH_TRACE_ERROR(...)                                     \
  {                                                               \
+0 −3
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@
#include "bte.h"
#include "btm_api.h"
#include "btu.h"
#include "gap_api.h"
#include "l2c_api.h"
#include "main_int.h"
#include "osi/include/config.h"
@@ -123,8 +122,6 @@ static tBTTRC_FUNC_MAP bttrc_set_level_map[] = {
    {BTTRC_ID_STK_HID, BTTRC_ID_STK_HID, HID_HostSetTraceLevel, "TRC_HID_HOST",
     DEFAULT_CONF_TRACE_LEVEL},
#endif
    {BTTRC_ID_STK_GAP, BTTRC_ID_STK_GAP, GAP_SetTraceLevel, "TRC_GAP",
     DEFAULT_CONF_TRACE_LEVEL},
#if (PAN_INCLUDED == TRUE)
    {BTTRC_ID_STK_PAN, BTTRC_ID_STK_PAN, PAN_SetTraceLevel, "TRC_PAN",
     DEFAULT_CONF_TRACE_LEVEL},
+0 −22
Original line number Diff line number Diff line
@@ -24,22 +24,6 @@

tGAP_CB gap_cb;

/*******************************************************************************
 *
 * Function         GAP_SetTraceLevel
 *
 * Description      This function sets the trace level for GAP.  If called with
 *                  a value of 0xFF, it simply returns the current trace level.
 *
 * Returns          The new or current trace level
 *
 ******************************************************************************/
uint8_t GAP_SetTraceLevel(uint8_t new_level) {
  if (new_level != 0xFF) gap_cb.trace_level = new_level;

  return (gap_cb.trace_level);
}

/*******************************************************************************
 *
 * Function         GAP_Init
@@ -55,12 +39,6 @@ uint8_t GAP_SetTraceLevel(uint8_t new_level) {
void GAP_Init(void) {
  memset(&gap_cb, 0, sizeof(tGAP_CB));

#if defined(GAP_INITIAL_TRACE_LEVEL)
  gap_cb.trace_level = GAP_INITIAL_TRACE_LEVEL;
#else
  gap_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */
#endif

  gap_conn_init();
  gap_attr_db_init();
}
+28 −24
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
 ******************************************************************************/
#include "bt_target.h"

#include <base/strings/stringprintf.h>
#include <string.h>
#include <array>
#include <list>
@@ -32,6 +33,8 @@
#include "hcimsgs.h"
#include "osi/include/osi.h"

using base::StringPrintf;

namespace {

typedef struct {
@@ -145,8 +148,7 @@ tGATT_STATUS read_attr_value(uint16_t handle, tGATT_VALUE* p_value,
            p_value->len -= offset;
            p_dev_name += offset;
            ARRAY_TO_STREAM(p, p_dev_name, p_value->len);
            GAP_TRACE_EVENT("GATT_UUID_GAP_DEVICE_NAME len=0x%04x",
                            p_value->len);
            DVLOG(1) << "GATT_UUID_GAP_DEVICE_NAME len=" << +p_value->len;
          }
          break;

@@ -199,7 +201,7 @@ void server_attr_request_cback(uint16_t conn_id, uint32_t trans_id,
  uint8_t status = GATT_INVALID_PDU;
  bool ignore = false;

  GAP_TRACE_EVENT("%s: recv type (0x%02x)", __func__, type);
  DVLOG(1) << StringPrintf("%s: recv type (0x%02x)", __func__, type);

  tGATTS_RSP rsp_msg;
  memset(&rsp_msg, 0, sizeof(tGATTS_RSP));
@@ -219,16 +221,17 @@ void server_attr_request_cback(uint16_t conn_id, uint32_t trans_id,

    case GATTS_REQ_TYPE_WRITE_EXEC:
      ignore = true;
      GAP_TRACE_EVENT("Ignore GATTS_REQ_TYPE_WRITE_EXEC");
      DVLOG(1) << "Ignore GATTS_REQ_TYPE_WRITE_EXEC";
      break;

    case GATTS_REQ_TYPE_MTU:
      GAP_TRACE_EVENT("Get MTU exchange new mtu size: %d", p_data->mtu);
      DVLOG(1) << "Get MTU exchange new mtu size: " << +p_data->mtu;
      ignore = true;
      break;

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

@@ -270,13 +273,13 @@ void cl_op_cmpl(tGAP_CLCB& clcb, bool status, uint16_t len, uint8_t* p_name) {
  tGAP_BLE_CMPL_CBACK* p_cback = clcb.p_cback;
  uint16_t op = clcb.cl_op_uuid;

  GAP_TRACE_EVENT("%s: status: %d", __func__, status);
  DVLOG(1) << StringPrintf("%s: status: %d", __func__, status);

  clcb.cl_op_uuid = 0;
  clcb.p_cback = NULL;

  if (p_cback && op) {
    GAP_TRACE_EVENT("%s: calling", __func__);
    DVLOG(1) << __func__ << ": calling";
    (*p_cback)(status, clcb.bda, len, (char*)p_name);
  }

@@ -322,8 +325,9 @@ void client_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status,

  op_type = p_clcb->cl_op_uuid;

  GAP_TRACE_EVENT("%s: - op_code: 0x%02x  status: 0x%02x  read_type: 0x%04x",
                  __func__, op, status, op_type);
  DVLOG(1) << StringPrintf(
      "%s: - op_code: 0x%02x  status: 0x%02x  read_type: 0x%04x", __func__, op,
      status, op_type);
  /* Currently we only issue read commands */
  if (op != GATTC_OPTYPE_READ) return;

@@ -367,7 +371,7 @@ bool accept_client_operation(BD_ADDR peer_bda, uint16_t uuid,
    p_clcb = clcb_alloc(peer_bda);
  }

  GAP_TRACE_EVENT("%s() - BDA: %08x%04x  cl_op_uuid: 0x%04x", __func__,
  DVLOG(1) << StringPrintf("%s() - BDA: %08x%04x  cl_op_uuid: 0x%04x", __func__,
                          (peer_bda[0] << 24) + (peer_bda[1] << 16) +
                              (peer_bda[2] << 8) + peer_bda[3],
                          (peer_bda[4] << 8) + peer_bda[5], uuid);
@@ -446,7 +450,7 @@ void gap_attr_db_init(void) {
                   sizeof(service) / sizeof(btgatt_db_element_t));
  service_handle = service[0].attribute_handle;

  GAP_TRACE_EVENT("%s: service_handle = %d", __func__, service_handle);
  DVLOG(1) << __func__ << ": service_handle = " << +service_handle;

  gatt_attr[0].uuid = GATT_UUID_GAP_DEVICE_NAME;
  gatt_attr[0].handle = service[1].attribute_handle;
@@ -478,11 +482,11 @@ void gap_attr_db_init(void) {
 *
 ******************************************************************************/
void GAP_BleAttrDBUpdate(uint16_t attr_uuid, tGAP_BLE_ATTR_VALUE* p_value) {
  GAP_TRACE_EVENT("%s: attr_uuid=0x%04x", __func__, attr_uuid);
  DVLOG(1) << StringPrintf("%s: attr_uuid=0x%04x", __func__, attr_uuid);

  for (tGAP_ATTR& db_attr : gatt_attr) {
    if (db_attr.uuid == attr_uuid) {
      GAP_TRACE_EVENT("Found attr_uuid=0x%04x", attr_uuid);
      DVLOG(1) << StringPrintf("Found attr_uuid=0x%04x", attr_uuid);

      switch (attr_uuid) {
        case GATT_UUID_GAP_ICON:
@@ -565,20 +569,20 @@ bool GAP_BleReadPeerAddressResolutionCap(BD_ADDR peer_bda,
bool GAP_BleCancelReadPeerDevName(BD_ADDR peer_bda) {
  tGAP_CLCB* p_clcb = find_clcb_by_bd_addr(peer_bda);

  GAP_TRACE_EVENT("%s: BDA: %08x%04x  cl_op_uuid: 0x%04x", __func__,
  DVLOG(1) << StringPrintf("%s: BDA: %08x%04x  cl_op_uuid: 0x%04x", __func__,
                          (peer_bda[0] << 24) + (peer_bda[1] << 16) +
                              (peer_bda[2] << 8) + peer_bda[3],
                          (peer_bda[4] << 8) + peer_bda[5],
                          (p_clcb == NULL) ? 0 : p_clcb->cl_op_uuid);

  if (p_clcb == NULL) {
    GAP_TRACE_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)) {
      GAP_TRACE_ERROR("Cannot cancel where No connection id");
      LOG(ERROR) << "Cannot cancel where No connection id";
      return false;
    }
  }
+27 −26
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
 *
 ******************************************************************************/

#include <base/strings/stringprintf.h>
#include <string.h>
#include "bt_target.h"
#include "bt_utils.h"
@@ -27,6 +28,8 @@
#include "osi/include/osi.h"
#include "btm_int.h"

using base::StringPrintf;

/******************************************************************************/
/*            L O C A L    F U N C T I O N     P R O T O T Y P E S            */
/******************************************************************************/
@@ -132,7 +135,7 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id,
  tGAP_CCB* p_ccb;
  uint16_t cid;

  GAP_TRACE_EVENT("GAP_CONN - Open Request");
  DVLOG(1) << "GAP_CONN - Open Request";

  /* Allocate a new CCB. Return if none available. */
  p_ccb = gap_allocate_ccb();
@@ -156,8 +159,7 @@ 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);
    GAP_TRACE_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);
  }

@@ -192,7 +194,7 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id,
        L2CA_REGISTER(psm, &gap_cb.conn.reg_info,
                      AMP_AUTOSWITCH_ALLOWED | AMP_USE_AMP_IF_POSSIBLE);
    if (p_ccb->psm == 0) {
      GAP_TRACE_ERROR("%s: Failure registering PSM 0x%04x", __func__, psm);
      LOG(ERROR) << StringPrintf("%s: Failure registering PSM 0x%04x", __func__, psm);
      gap_release_ccb(p_ccb);
      return (GAP_INVALID_HANDLE);
    }
@@ -203,7 +205,7 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id,
        L2CA_REGISTER_COC(psm, &gap_cb.conn.reg_info,
                          AMP_AUTOSWITCH_ALLOWED | AMP_USE_AMP_IF_POSSIBLE);
    if (p_ccb->psm == 0) {
      GAP_TRACE_ERROR("%s: Failure registering PSM 0x%04x", __func__, psm);
      LOG(ERROR) << StringPrintf("%s: Failure registering PSM 0x%04x", __func__, psm);
      gap_release_ccb(p_ccb);
      return (GAP_INVALID_HANDLE);
    }
@@ -213,7 +215,7 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id,
  p_ccb->service_id = service_id;
  if (!BTM_SetSecurityLevel((uint8_t)!is_server, p_serv_name, p_ccb->service_id,
                            security, p_ccb->psm, 0, 0)) {
    GAP_TRACE_ERROR("GAP_CONN - Security Error");
    LOG(ERROR) << "GAP_CONN - Security Error";
    gap_release_ccb(p_ccb);
    return (GAP_INVALID_HANDLE);
  }
@@ -292,7 +294,7 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id,
uint16_t GAP_ConnClose(uint16_t gap_handle) {
  tGAP_CCB* p_ccb = gap_find_ccb_by_handle(gap_handle);

  GAP_TRACE_EVENT("GAP_CONN - close  handle: 0x%x", gap_handle);
  DVLOG(1) << StringPrintf("GAP_CONN - close  handle: 0x%x", gap_handle);

  if (p_ccb) {
    /* Check if we have a connection ID */
@@ -362,7 +364,7 @@ uint16_t GAP_ConnReadData(uint16_t gap_handle, uint8_t* p_data,

  mutex_global_unlock();

  GAP_TRACE_EVENT("GAP_ConnReadData - rx_queue_size left=%d, *p_len=%d",
  DVLOG(1) << StringPrintf("GAP_ConnReadData - rx_queue_size left=%d, *p_len=%d",
                  p_ccb->rx_queue_size, *p_len);

  return (BT_PASS);
@@ -394,7 +396,7 @@ int GAP_GetRxQueueCnt(uint16_t handle, uint32_t* p_rx_queue_count) {
  } else
    rc = GAP_INVALID_HANDLE;

  GAP_TRACE_EVENT("GAP_GetRxQueueCnt - rc = 0x%04x, rx_queue_count=%d", rc,
  DVLOG(1) << StringPrintf("GAP_GetRxQueueCnt - rc = 0x%04x, rx_queue_count=%d", rc,
                  *p_rx_queue_count);

  return (rc);
@@ -480,7 +482,7 @@ uint16_t GAP_ConnWriteData(uint16_t gap_handle, uint8_t* p_data,
    max_len -= p_buf->len;
    p_data += p_buf->len;

    GAP_TRACE_EVENT("GAP_WriteData %d bytes", p_buf->len);
    DVLOG(1) << StringPrintf("GAP_WriteData %d bytes", p_buf->len);

    fixed_queue_enqueue(p_ccb->tx_queue, p_buf);
  }
@@ -580,10 +582,10 @@ uint16_t GAP_ConnSetIdleTimeout(uint16_t gap_handle, uint16_t timeout) {
uint8_t* GAP_ConnGetRemoteAddr(uint16_t gap_handle) {
  tGAP_CCB* p_ccb = gap_find_ccb_by_handle(gap_handle);

  GAP_TRACE_EVENT("GAP_ConnGetRemoteAddr gap_handle = %d", gap_handle);
  DVLOG(1) << StringPrintf("GAP_ConnGetRemoteAddr gap_handle = %d", gap_handle);

  if ((p_ccb) && (p_ccb->con_state > GAP_CCB_STATE_LISTENING)) {
    GAP_TRACE_EVENT(
    DVLOG(1) << StringPrintf(
        "GAP_ConnGetRemoteAddr bda "
        ":0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
        p_ccb->rem_dev_address[0], p_ccb->rem_dev_address[1],
@@ -591,7 +593,7 @@ uint8_t* GAP_ConnGetRemoteAddr(uint16_t gap_handle) {
        p_ccb->rem_dev_address[4], p_ccb->rem_dev_address[5]);
    return (p_ccb->rem_dev_address);
  } else {
    GAP_TRACE_EVENT("GAP_ConnGetRemoteAddr return Error ");
    DVLOG(1) << StringPrintf("GAP_ConnGetRemoteAddr return Error ");
    return (NULL);
  }
}
@@ -653,7 +655,7 @@ void gap_tx_complete_ind(uint16_t l2cap_cid, uint16_t sdu_sent) {
  if (p_ccb == NULL) return;

  if ((p_ccb->con_state == GAP_CCB_STATE_CONNECTED) && (sdu_sent == 0xFFFF)) {
    GAP_TRACE_EVENT("%s: GAP_EVT_TX_EMPTY", __func__);
    DVLOG(1) << StringPrintf("%s: GAP_EVT_TX_EMPTY", __func__);
    p_ccb->p_callback(p_ccb->gap_handle, GAP_EVT_TX_EMPTY);
  }
}
@@ -684,10 +686,9 @@ static void gap_connect_ind(BD_ADDR bd_addr, uint16_t l2cap_cid, uint16_t psm,
  }

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

    /* Disconnect because it is an unexpected connection */
    L2CA_DISCONNECT_REQ(l2cap_cid);
@@ -721,7 +722,7 @@ static void gap_connect_ind(BD_ADDR bd_addr, uint16_t l2cap_cid, uint16_t psm,
    gap_checks_con_flags(p_ccb);
  }

  GAP_TRACE_EVENT("GAP_CONN - Rcvd L2CAP conn ind, CID: 0x%x",
  DVLOG(1) << StringPrintf("GAP_CONN - Rcvd L2CAP conn ind, CID: 0x%x",
                  p_ccb->connection_id);

  /* Send a Configuration Request. */
@@ -740,7 +741,7 @@ static void gap_connect_ind(BD_ADDR bd_addr, uint16_t l2cap_cid, uint16_t psm,
 *
 ******************************************************************************/
static void gap_checks_con_flags(tGAP_CCB* p_ccb) {
  GAP_TRACE_EVENT("gap_checks_con_flags conn_flags:0x%x, ", p_ccb->con_flags);
  DVLOG(1) << __func__ << " conn_flags:0x" << +p_ccb->con_flags;
  /* if all the required con_flags are set, report the OPEN event now */
  if ((p_ccb->con_flags & GAP_CCB_FLAGS_CONN_DONE) == GAP_CCB_FLAGS_CONN_DONE) {
    p_ccb->con_state = GAP_CCB_STATE_CONNECTED;
@@ -764,7 +765,7 @@ static void gap_sec_check_complete(UNUSED_ATTR BD_ADDR bd_addr,
                                   void* p_ref_data, uint8_t res) {
  tGAP_CCB* p_ccb = (tGAP_CCB*)p_ref_data;

  GAP_TRACE_EVENT(
  DVLOG(1) << StringPrintf(
      "gap_sec_check_complete conn_state:%d, conn_flags:0x%x, status:%d",
      p_ccb->con_state, p_ccb->con_flags, res);
  if (p_ccb->con_state == GAP_CCB_STATE_IDLE) return;
@@ -923,7 +924,7 @@ static void gap_config_cfm(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) {
static void gap_disconnect_ind(uint16_t l2cap_cid, bool ack_needed) {
  tGAP_CCB* p_ccb;

  GAP_TRACE_EVENT("GAP_CONN - Rcvd L2CAP disc, CID: 0x%x", l2cap_cid);
  DVLOG(1) << StringPrintf("GAP_CONN - Rcvd L2CAP disc, CID: 0x%x", l2cap_cid);

  /* Find CCB based on CID */
  p_ccb = gap_find_ccb_by_cid(l2cap_cid);
@@ -959,7 +960,7 @@ static void gap_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg) {

    p_ccb->rx_queue_size += p_msg->len;
    /*
    GAP_TRACE_EVENT ("gap_data_ind - rx_queue_size=%d, msg len=%d",
    DVLOG(1) << StringPrintf ("gap_data_ind - rx_queue_size=%d, msg len=%d",
                                   p_ccb->rx_queue_size, p_msg->len);
     */

@@ -983,7 +984,7 @@ static void gap_congestion_ind(uint16_t lcid, bool is_congested) {
  BT_HDR* p_buf;
  uint8_t status;

  GAP_TRACE_EVENT("GAP_CONN - Rcvd L2CAP Is Congested (%d), CID: 0x%x",
  DVLOG(1) << StringPrintf("GAP_CONN - Rcvd L2CAP Is Congested (%d), CID: 0x%x",
                  is_congested, lcid);

  /* Find CCB based on CID */
@@ -1121,8 +1122,8 @@ static void gap_release_ccb(tGAP_CCB* p_ccb) {
  for (uint16_t i = 0; i < GAP_MAX_CONNECTIONS; i++, p_ccb_local++) {
    if ((p_ccb_local->con_state != GAP_CCB_STATE_IDLE) &&
        (p_ccb_local->psm == p_ccb->psm)) {
      GAP_TRACE_EVENT("%s :%d PSM is still in use, do not deregister",
                      __func__, p_ccb_local->psm);
      DVLOG(1) << __func__ << " : " << +p_ccb_local->psm
              << " PSM is still in use, do not deregister";
      return;
    }
  }
Loading