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

Commit 89d49ce5 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

bta_gattc: Add dumpsys for bta_gattc_cb

Allows to debug legacy code.

BTA_GATTC_CB state BTA_GATTC_STATE_ENABLED
 ->conn_track (GATT_MAX_PHY_CHANNEL=7)
  -- used: 0
 ->bg_track (BTA_GATTC_KNOWN_SR_MAX=255)
  address: xx:xx:xx:xx:7c:9f  cif_mask: 0x00000410
  address: xx:xx:xx:xx:13:0d  cif_mask: 0x00000400
  address: xx:xx:xx:xx:13:1e  cif_mask: 0x00000400
  address: xx:xx:xx:xx:1d:c7  cif_mask: 0x00000400
  address: xx:xx:xx:xx:0d:81  cif_mask: 0x00000400
  address: xx:xx:xx:xx:37:e7  cif_mask: 0x00000400
  address: xx:xx:xx:xx:62:cd  cif_mask: 0x00000400
  address: xx:xx:xx:xx:7a:0e  cif_mask: 0x00000400
  address: xx:xx:xx:xx:bf:c8  cif_mask: 0x00000400
  -- used: 9
 ->cl_rcb (BTA_GATTC_CL_MAX=32)
  client_if: 3  app uuids: 653e2c09-1998-7135-6170-09e6e5c33762  clcb_num: 0
  client_if: 4  app uuids: 52fa4f05-c872-2a5f-8fd3-325a1ed91a27  clcb_num: 2
  client_if: 5  app uuids: ca641ade-f5ee-9f3f-e9c3-f8b85495f168  clcb_num: 0
  client_if: 6  app uuids: 0d45ce8d-27af-9647-5e5a-b9a0cbc158b7  clcb_num: 0
  client_if: 7  app uuids: ee1564af-219f-9a9c-6f91-94e975e660fc  clcb_num: 0
  client_if: 10  app uuids: a11452b9-abe0-dba7-d875-4bf84b4e9e17  clcb_num: 2
  client_if: 11  app uuids: 55ffb127-03cf-c200-8e7a-818cf246971c  clcb_num: 2
  client_if: 13  app uuids: 303edfa5-682c-8348-c0a4-e07d91d39779  clcb_num: 1
  client_if: 14  app uuids: de3c7659-a0e0-7252-a2ce-608d06146b60  clcb_num: 1
  client_if: 15  app uuids: eac72e2b-8055-fb15-f362-c4ed867bbeba  clcb_num: 1
  client_if: 16  app uuids: 972046ea-7c04-ff1e-f1fa-a12fc41ff356  clcb_num: 1
  client_if: 17  app uuids: ab1d4efe-172a-7811-adc4-c3d0aa753514  clcb_num: 1
  client_if: 18  app uuids: c4d63275-a9af-c2e8-90f6-51cb12bb3e99  clcb_num: 1
  client_if: 19  app uuids: 7525f060-00bf-1c94-880c-426d3543ac13  clcb_num: 1
  client_if: 20  app uuids: fece1e72-b3a4-a9c6-08df-f103f87d412c  clcb_num: 1
  -- used: 15
 ->clcb (BTA_GATTC_CLCB_MAX=22)
  conn_id: 0x0114  address: xx:xx:xx:xx:13:1e  transport: BT_TRANSPORT_LE  state: BTA_GATTC_CONN_ST
  conn_id: 0x0004  address: xx:xx:xx:xx:13:0d  transport: BT_TRANSPORT_LE  state: BTA_GATTC_CONN_ST
  conn_id: 0x0104  address: xx:xx:xx:xx:13:1e  transport: BT_TRANSPORT_LE  state: BTA_GATTC_CONN_ST
  conn_id: 0x000a  address: xx:xx:xx:xx:13:0d  transport: BT_TRANSPORT_LE  state: BTA_GATTC_CONN_ST
  conn_id: 0x010a  address: xx:xx:xx:xx:13:1e  transport: BT_TRANSPORT_LE  state: BTA_GATTC_CONN_ST
  conn_id: 0x000b  address: xx:xx:xx:xx:13:0d  transport: BT_TRANSPORT_LE  state: BTA_GATTC_CONN_ST
  conn_id: 0x010b  address: xx:xx:xx:xx:13:1e  transport: BT_TRANSPORT_LE  state: BTA_GATTC_CONN_ST
  conn_id: 0x000d  address: xx:xx:xx:xx:13:0d  transport: BT_TRANSPORT_LE  state: BTA_GATTC_CONN_ST
  conn_id: 0x010e  address: xx:xx:xx:xx:13:1e  transport: BT_TRANSPORT_LE  state: BTA_GATTC_CONN_ST
  conn_id: 0x000f  address: xx:xx:xx:xx:13:0d  transport: BT_TRANSPORT_LE  state: BTA_GATTC_CONN_ST
  conn_id: 0x0010  address: xx:xx:xx:xx:13:0d  transport: BT_TRANSPORT_LE  state: BTA_GATTC_CONN_ST
  conn_id: 0x0011  address: xx:xx:xx:xx:13:0d  transport: BT_TRANSPORT_LE  state: BTA_GATTC_CONN_ST
  conn_id: 0x0112  address: xx:xx:xx:xx:13:1e  transport: BT_TRANSPORT_LE  state: BTA_GATTC_CONN_ST
  conn_id: 0x0113  address: xx:xx:xx:xx:13:1e  transport: BT_TRANSPORT_LE  state: BTA_GATTC_CONN_ST
  -- used: 14
 ->known_server (BTA_GATTC_KNOWN_SR_MAX=255)
  server_address: xx:xx:xx:xx:1d:c7  mtu: 0  blocked_conn_id: 000000  pending_discovery:   num_clcb: 0  state: BTA_GATTC_SERV_IDLE  connecte
d: 0  srvc_disc_count:

Bug: 325438660
Test: mmm packages/modules/Bluetooth
Test: sanity Bluetooth operations
Flag: Exempt, debug code only
Change-Id: I9373ca662baa4d92a5ac65a27a0c13ca7048e930
parent 18bd5901
Loading
Loading
Loading
Loading
+55 −13
Original line number Diff line number Diff line
@@ -86,6 +86,14 @@ typedef uint16_t tBTA_GATTC_INT_EVT;

#define BTA_GATTC_WRITE_PREPARE GATT_WRITE_PREPARE

typedef enum : uint8_t {
  BTA_GATTC_SERV_IDLE = 0,
  BTA_GATTC_SERV_LOAD,
  BTA_GATTC_SERV_SAVE,
  BTA_GATTC_SERV_DISC,
  BTA_GATTC_SERV_DISC_ACT
} tBTA_GATTC_SERV_STATE;

/* internal strucutre for GATTC register API  */
typedef struct {
  BT_HDR_RIGID hdr;
@@ -211,26 +219,19 @@ typedef union {
  tBTA_GATTC_INT_CONN int_conn;
} tBTA_GATTC_DATA;

enum {
typedef enum : uint8_t {
  BTA_GATTC_IDLE_ST = 0, /* Idle  */
  BTA_GATTC_W4_CONN_ST,  /* Wait for connection -  (optional) */
  BTA_GATTC_CONN_ST,     /* connected state */
  BTA_GATTC_DISCOVER_ST  /* discover is in progress */
};
typedef uint8_t tBTA_GATTC_STATE;
} tBTA_GATTC_STATE;

typedef struct {
  bool in_use;
  RawAddress server_bda;
  bool connected;

#define BTA_GATTC_SERV_IDLE 0
#define BTA_GATTC_SERV_LOAD 1
#define BTA_GATTC_SERV_SAVE 2
#define BTA_GATTC_SERV_DISC 3
#define BTA_GATTC_SERV_DISC_ACT 4

  uint8_t state;
  tBTA_GATTC_SERV_STATE state;

  gatt::Database gatt_database;
  uint8_t update_count; /* indication received */
@@ -325,15 +326,15 @@ typedef struct {
  RawAddress remote_bda;
} tBTA_GATTC_CONN;

enum {
typedef enum : uint8_t {
  BTA_GATTC_STATE_DISABLED,
  BTA_GATTC_STATE_ENABLING,
  BTA_GATTC_STATE_ENABLED,
  BTA_GATTC_STATE_DISABLING
};
} tBTA_GATTC_CB_STATE;

typedef struct {
  uint8_t state;
  tBTA_GATTC_CB_STATE state;

  tBTA_GATTC_CONN conn_track[GATT_MAX_PHY_CHANNEL];
  tBTA_GATTC_BG_TCK bg_track[BTA_GATTC_KNOWN_SR_MAX];
@@ -523,8 +524,49 @@ void bta_gattc_cache_write(const RawAddress& server_bda,
void bta_gattc_cache_link(const RawAddress& server_bda, const Octet16& hash);
void bta_gattc_cache_reset(const RawAddress& server_bda);

inline std::string bta_clcb_state_text(const tBTA_GATTC_STATE& state) {
  switch (state) {
    CASE_RETURN_TEXT(BTA_GATTC_IDLE_ST);
    CASE_RETURN_TEXT(BTA_GATTC_W4_CONN_ST);
    CASE_RETURN_TEXT(BTA_GATTC_CONN_ST);
    CASE_RETURN_TEXT(BTA_GATTC_DISCOVER_ST);
    default:
      return base::StringPrintf("UNKNOWN[%hhu]", state);
  }
}

inline std::string bta_server_state_text(const tBTA_GATTC_SERV_STATE& state) {
  switch (state) {
    CASE_RETURN_TEXT(BTA_GATTC_SERV_IDLE);
    CASE_RETURN_TEXT(BTA_GATTC_SERV_LOAD);
    CASE_RETURN_TEXT(BTA_GATTC_SERV_SAVE);
    CASE_RETURN_TEXT(BTA_GATTC_SERV_DISC);
    CASE_RETURN_TEXT(BTA_GATTC_SERV_DISC_ACT);
    default:
      return base::StringPrintf("UNKNOWN[%hhu]", state);
  }
}

inline std::string bta_gattc_state_text(const tBTA_GATTC_CB_STATE& state) {
  switch (state) {
    CASE_RETURN_TEXT(BTA_GATTC_STATE_DISABLED);
    CASE_RETURN_TEXT(BTA_GATTC_STATE_ENABLING);
    CASE_RETURN_TEXT(BTA_GATTC_STATE_ENABLED);
    CASE_RETURN_TEXT(BTA_GATTC_STATE_DISABLING);
    default:
      return base::StringPrintf("UNKNOWN[%hhu]", state);
  }
}

namespace fmt {
template <>
struct formatter<tBTA_GATTC_CB_STATE> : enum_formatter<tBTA_GATTC_CB_STATE> {};
template <>
struct formatter<tBTA_GATTC_SERV_STATE>
    : enum_formatter<tBTA_GATTC_SERV_STATE> {};
template <>
struct formatter<tBTA_GATTC_STATE> : enum_formatter<tBTA_GATTC_STATE> {};
template <>
struct formatter<RobustCachingSupport> : enum_formatter<RobustCachingSupport> {
};
}  // namespace fmt
+1 −1
Original line number Diff line number Diff line
@@ -321,7 +321,7 @@ bool bta_gattc_sm_execute(tBTA_GATTC_CLCB* p_clcb, uint16_t event,
  event &= 0x00FF;

  /* set next state */
  p_clcb->state = state_table[event][BTA_GATTC_NEXT_STATE];
  p_clcb->state = (tBTA_GATTC_STATE)(state_table[event][BTA_GATTC_NEXT_STATE]);

  /* execute action functions */
  for (i = 0; i < BTA_GATTC_ACTIONS; i++) {
+99 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include "common/init_flags.h"
#include "device/include/controller.h"
#include "internal_include/bt_target.h"
#include "internal_include/bt_trace.h"
#include "os/log.h"
#include "osi/include/allocator.h"
#include "types/bt_transport.h"
@@ -813,3 +814,101 @@ tBTA_GATTC_CLCB* bta_gattc_find_int_disconn_clcb(tBTA_GATTC_DATA* p_msg) {
bool bta_gattc_is_robust_caching_enabled() {
  return bluetooth::common::init_flags::gatt_robust_caching_client_is_enabled();
}

void bta_gatt_client_dump(int fd) {
  std::stringstream stream;
  int entry_count = 0;

  stream << " ->conn_track (GATT_MAX_PHY_CHANNEL=" << GATT_MAX_PHY_CHANNEL
         << ")\n";
  for (int i = 0; i < GATT_MAX_PHY_CHANNEL; i++) {
    tBTA_GATTC_CONN* p_conn_track = &bta_gattc_cb.conn_track[i];
    if (p_conn_track->in_use) {
      entry_count++;
      stream << "  address: "
             << ADDRESS_TO_LOGGABLE_STR(p_conn_track->remote_bda);
      stream << "\n";
    }
  }
  stream << "  -- used: " << entry_count << "\n";
  entry_count = 0;

  stream << " ->bg_track (BTA_GATTC_KNOWN_SR_MAX=" << BTA_GATTC_KNOWN_SR_MAX
         << ")\n";
  for (int i = 0; i < BTA_GATTC_KNOWN_SR_MAX; i++) {
    tBTA_GATTC_BG_TCK* p_bg_track = &bta_gattc_cb.bg_track[i];
    if (!p_bg_track->in_use) {
      continue;
    }
    entry_count++;
    stream << "  address: " << ADDRESS_TO_LOGGABLE_STR(p_bg_track->remote_bda)
           << "  cif_mask: " << loghex(p_bg_track->cif_mask);
    stream << "\n";
  }

  stream << "  -- used: " << entry_count << "\n";
  entry_count = 0;
  stream << " ->cl_rcb (BTA_GATTC_CL_MAX=" << BTA_GATTC_CL_MAX << ")\n";
  for (int i = 0; i < BTA_GATTC_CL_MAX; i++) {
    tBTA_GATTC_RCB* p_cl_rcb = &bta_gattc_cb.cl_rcb[i];
    if (!p_cl_rcb->in_use) {
      continue;
    }
    entry_count++;
    stream << "  client_if: " << +p_cl_rcb->client_if
           << "  app uuids: " << p_cl_rcb->app_uuid
           << "  clcb_num: " << +p_cl_rcb->num_clcb;
    stream << "\n";
  }

  stream << "  -- used: " << entry_count << "\n";
  entry_count = 0;
  stream << " ->clcb (BTA_GATTC_CLCB_MAX=" << BTA_GATTC_CLCB_MAX << ")\n";
  for (int i = 0; i < BTA_GATTC_CLCB_MAX; i++) {
    tBTA_GATTC_CLCB* p_clcb = &bta_gattc_cb.clcb[i];
    if (!p_clcb->in_use) {
      continue;
    }
    entry_count++;
    stream << "  conn_id: " << loghex(p_clcb->bta_conn_id)
           << "  address: " << ADDRESS_TO_LOGGABLE_STR(p_clcb->bda)
           << "  transport: " << bt_transport_text(p_clcb->transport)
           << "  state: " << bta_clcb_state_text(p_clcb->state);
    stream << "\n";
  }

  stream << "  -- used: " << entry_count << "\n";
  entry_count = 0;
  stream << " ->known_server (BTA_GATTC_KNOWN_SR_MAX=" << BTA_GATTC_KNOWN_SR_MAX
         << ")\n";
  for (int i = 0; i < BTA_GATTC_CL_MAX; i++) {
    tBTA_GATTC_SERV* p_known_server = &bta_gattc_cb.known_server[i];
    if (!p_known_server->in_use) {
      continue;
    }
    entry_count++;
    stream << "  server_address: "
           << ADDRESS_TO_LOGGABLE_STR(p_known_server->server_bda)
           << "  mtu: " << p_known_server->mtu
           << "  blocked_conn_id: " << loghex(p_known_server->blocked_conn_id)
           << "  pending_discovery: "
           << p_known_server->pending_discovery.ToString()
           << "  num_clcb: " << +p_known_server->num_clcb
           << "  state: " << bta_server_state_text(p_known_server->state)
           << "  connected: " << p_known_server->connected
           << "  srvc_disc_count: " << p_known_server->srvc_disc_count
           << "  disc_blocked_waiting_on_version: "
           << p_known_server->disc_blocked_waiting_on_version
           << "  srvc_hdl_chg: " << +p_known_server->srvc_hdl_chg
           << "  srvc_hdl_db_hash: " << p_known_server->srvc_hdl_db_hash
           << "  update_count: " << +p_known_server->update_count;

    stream << "\n";
  }

  stream << "  -- used: " << entry_count << "\n";
  entry_count = 0;
  dprintf(fd, "BTA_GATTC_CB state %s \n%s\n",
          bta_gattc_state_text(bta_gattc_cb.state).c_str(),
          stream.str().c_str());
}
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -182,6 +182,7 @@ bt_status_t btif_hh_connect(const tAclLinkSpec* link_spec);
bt_status_t btif_hd_execute_service(bool b_enable);

extern void gatt_tcb_dump(int fd);
extern void bta_gatt_client_dump(int fd);

/*******************************************************************************
 *  Callbacks from bluetooth::core (see go/invisalign-bt)
@@ -824,6 +825,7 @@ static void dump(int fd, const char** arguments) {
  bluetooth::avrcp::AvrcpService::DebugDump(fd);
  btif_debug_config_dump(fd);
  gatt_tcb_dump(fd);
  bta_gatt_client_dump(fd);
  device_debug_iot_config_dump(fd);
  BTA_HfClientDumpStatistics(fd);
  wakelock_debug_dump(fd);
+1 −0
Original line number Diff line number Diff line
@@ -188,3 +188,4 @@ void bta_gattc_continue_discovery_if_needed(const RawAddress& /* bd_addr */,
                                            uint16_t /* acl_handle */) {
  inc_func_call_count(__func__);
}
void bta_gatt_client_dump(int /* fd */) { inc_func_call_count(__func__); }