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

Commit 1853c14e authored by Chris Manton's avatar Chris Manton
Browse files

stack::sdp Add dump sdp control blocks

Bug: 352080249
Test: atest net_test_stack_sdp
Flag: EXEMPT, Test Infrastructure and Logging

Change-Id: I4486fb45215c6765380357627c94231c8ded9ce9
parent d6810480
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -60,6 +60,8 @@ static void sdp_connect_ind(const RawAddress& bd_addr, uint16_t l2cap_cid, uint1
                            uint8_t /* l2cap_id */) {
  tCONN_CB* p_ccb = sdpu_allocate_ccb();
  if (p_ccb == NULL) {
    log::warn("no spare CCB for peer:{} cid:{}", bd_addr, l2cap_cid);
    sdpu_dump_all_ccb();
    return;
  }

@@ -74,6 +76,8 @@ static void sdp_connect_ind(const RawAddress& bd_addr, uint16_t l2cap_cid, uint1
static void sdp_on_l2cap_error(uint16_t l2cap_cid, uint16_t /* result */) {
  tCONN_CB* p_ccb = sdpu_find_ccb_by_cid(l2cap_cid);
  if (p_ccb == nullptr) {
    log::warn("SDP - Received l2cap error for unknown CID 0x{:x}", l2cap_cid);
    sdpu_dump_all_ccb();
    return;
  }
  sdp_disconnect(p_ccb, SDP_CFG_FAILED);
@@ -97,6 +101,7 @@ static void sdp_connect_cfm(uint16_t l2cap_cid, uint16_t result) {
  p_ccb = sdpu_find_ccb_by_cid(l2cap_cid);
  if (p_ccb == NULL) {
    log::warn("SDP - Rcvd conn cnf for unknown CID 0x{:x}", l2cap_cid);
    sdpu_dump_all_ccb();
    return;
  }

@@ -126,6 +131,7 @@ static void sdp_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) {
  p_ccb = sdpu_find_ccb_by_cid(l2cap_cid);
  if (p_ccb == NULL) {
    log::warn("SDP - Rcvd L2CAP cfg ind, unknown CID: 0x{:x}", l2cap_cid);
    sdpu_dump_all_ccb();
    return;
  }

@@ -165,6 +171,7 @@ static void sdp_config_cfm(uint16_t l2cap_cid, uint16_t /* initiator */, tL2CAP_
  p_ccb = sdpu_find_ccb_by_cid(l2cap_cid);
  if (p_ccb == NULL) {
    log::warn("SDP - Rcvd L2CAP cfg ind, unknown CID: 0x{:x}", l2cap_cid);
    sdpu_dump_all_ccb();
    return;
  }

@@ -196,6 +203,7 @@ static void sdp_disconnect_ind(uint16_t l2cap_cid, bool ack_needed) {
  p_ccb = sdpu_find_ccb_by_cid(l2cap_cid);
  if (p_ccb == NULL) {
    log::warn("SDP - Rcvd L2CAP disc, unknown CID: 0x{:x}", l2cap_cid);
    sdpu_dump_all_ccb();
    return;
  }
  tCONN_CB& ccb = *p_ccb;
@@ -248,6 +256,7 @@ static void sdp_data_ind(uint16_t l2cap_cid, BT_HDR* p_msg) {
    }
  } else {
    log::warn("SDP - Rcvd L2CAP data, unknown CID: 0x{:x}", l2cap_cid);
    sdpu_dump_all_ccb();
  }

  osi_free(p_msg);
@@ -357,6 +366,7 @@ static void sdp_disconnect_cfm(uint16_t l2cap_cid, uint16_t /* result */) {
  p_ccb = sdpu_find_ccb_by_cid(l2cap_cid);
  if (p_ccb == NULL) {
    log::warn("SDP - Rcvd L2CAP disc cfm, unknown CID: 0x{:x}", l2cap_cid);
    sdpu_dump_all_ccb();
    return;
  }
  tCONN_CB& ccb = *p_ccb;
+19 −0
Original line number Diff line number Diff line
@@ -419,6 +419,25 @@ void sdpu_release_ccb(tCONN_CB& ccb) {
  osi_free_and_reset((void**)&ccb.rsp_list);
}

/*******************************************************************************
 *
 * Function         sdpu_dump_all_ccb
 *
 * Description      Dump relevant data for all control blocks.
 *
 * Returns          void
 *
 ******************************************************************************/
void sdpu_dump_all_ccb() {
  uint16_t xx{};
  tCONN_CB* p_ccb{};

  for (xx = 0, p_ccb = sdp_cb.ccb; xx < SDP_MAX_CONNECTIONS; xx++, p_ccb++) {
    log::info("peer:{} cid:{} state:{} flags:{} ", p_ccb->device_address, p_ccb->connection_id,
              sdp_state_text(p_ccb->con_state), sdp_flags_text(p_ccb->con_flags));
  }
}

/*******************************************************************************
 *
 * Function         sdpu_get_active_ccb_cid
+1 −0
Original line number Diff line number Diff line
@@ -252,6 +252,7 @@ tCONN_CB* sdpu_find_ccb_by_cid(uint16_t cid);
tCONN_CB* sdpu_find_ccb_by_db(const tSDP_DISCOVERY_DB* p_db);
tCONN_CB* sdpu_allocate_ccb(void);
void sdpu_release_ccb(tCONN_CB& p_ccb);
void sdpu_dump_all_ccb();

uint8_t* sdpu_build_attrib_seq(uint8_t* p_out, uint16_t* p_attr, uint16_t num_attrs);
uint8_t* sdpu_build_attrib_entry(uint8_t* p_out, const tSDP_ATTRIBUTE* p_attr);
+16 −0
Original line number Diff line number Diff line
@@ -38,6 +38,10 @@ namespace {

static int L2CA_ConnectReqWithSecurity_cid = 0x42;
static RawAddress addr = RawAddress({0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6});
static RawAddress addr2 = RawAddress({0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6});
static RawAddress addr3 = RawAddress({0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6});
static RawAddress addr4 = RawAddress({0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6});
static RawAddress addr5 = RawAddress({0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6});
static tSDP_DISCOVERY_DB* sdp_db = nullptr;

class StackSdpWithMocksTest : public ::testing::Test {
@@ -399,3 +403,15 @@ TEST_F(SDP_GetDiRecord_Tests, SDP_GetDiRecord_Regression_test0) {
  ASSERT_EQ(device_info.rec.version, 0);
  ASSERT_FALSE(device_info.rec.primary_record);
}

TEST_F(StackSdpInitTest, sdpu_dump_all_ccb) {
  sdpu_dump_all_ccb();

  ASSERT_NE(nullptr, sdp_conn_originate(addr));
  ASSERT_NE(nullptr, sdp_conn_originate(addr2));
  ASSERT_NE(nullptr, sdp_conn_originate(addr3));
  ASSERT_NE(nullptr, sdp_conn_originate(addr4));
  ASSERT_EQ(nullptr, sdp_conn_originate(addr5));

  sdpu_dump_all_ccb();
}