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

Commit 4af4e092 authored by William Escande's avatar William Escande
Browse files

SDP Use reference instead of int / pointer

Change newly added method to directly take a reference of the ccb

Bug: 246022810
Test: atest net_test_stack_sdp
Tag: #refactor
Merged-In: Iea88fe7a1a8220c0a66b12c9cd103f9e2308ae25
Change-Id: Iea88fe7a1a8220c0a66b12c9cd103f9e2308ae25
(cherry picked from commit 832e05cf)
parent 38e5415b
Loading
Loading
Loading
Loading
+31 −28
Original line number Diff line number Diff line
@@ -256,21 +256,23 @@ static void sdp_disconnect_ind(uint16_t l2cap_cid, bool ack_needed) {
    SDP_TRACE_WARNING("SDP - Rcvd L2CAP disc, unknown CID: 0x%x", l2cap_cid);
    return;
  }
  tCONN_CB& ccb = *p_ccb;

  const tSDP_REASON reason =
      (ccb.con_state == SDP_STATE_CONNECTED) ? SDP_SUCCESS : SDP_CONN_FAILED;
  sdpu_callback(ccb, reason);

  sdpu_callback(p_ccb, (p_ccb->con_state == SDP_STATE_CONNECTED)
                           ? SDP_SUCCESS
                           : SDP_CONN_FAILED);
  if (ack_needed) {
    SDP_TRACE_WARNING("SDP - Rcvd L2CAP disc, process pend sdp ccb: 0x%x",
                      l2cap_cid);
    sdpu_process_pend_ccb(p_ccb->connection_id, false);
    sdpu_process_pend_ccb(ccb, false);
  } else {
    SDP_TRACE_WARNING("SDP - Rcvd L2CAP disc, clear pend sdp ccb: 0x%x",
                      l2cap_cid);
    sdpu_clear_pend_ccb(p_ccb->connection_id);
    sdpu_clear_pend_ccb(ccb);
  }

  sdpu_release_ccb(p_ccb);
  sdpu_release_ccb(ccb);
}

/*******************************************************************************
@@ -362,7 +364,7 @@ tCONN_CB* sdp_conn_originate(const RawAddress& p_bd_addr) {
  if (cid == 0) {
    SDP_TRACE_WARNING("%s: SDP - Originate failed for peer %s", __func__,
                      p_bd_addr.ToString().c_str());
    sdpu_release_ccb(p_ccb);
    sdpu_release_ccb(*p_ccb);
    return (NULL);
  }
  p_ccb->connection_id = cid;
@@ -379,26 +381,26 @@ tCONN_CB* sdp_conn_originate(const RawAddress& p_bd_addr) {
 *
 ******************************************************************************/
void sdp_disconnect(tCONN_CB* p_ccb, tSDP_REASON reason) {
  SDP_TRACE_EVENT("SDP - disconnect  CID: 0x%x", p_ccb->connection_id);
  tCONN_CB& ccb = *p_ccb;
  SDP_TRACE_EVENT("SDP - disconnect  CID: 0x%x", ccb.connection_id);

  /* Check if we have a connection ID */
  if (p_ccb->connection_id != 0) {
    p_ccb->disconnect_reason = reason;
    if (SDP_SUCCESS == reason &&
        (true == sdpu_process_pend_ccb(p_ccb->connection_id, true))) {
      sdpu_callback(p_ccb, reason);
      sdpu_release_ccb(p_ccb);
  if (ccb.connection_id != 0) {
    ccb.disconnect_reason = reason;
    if (SDP_SUCCESS == reason && sdpu_process_pend_ccb(ccb, true)) {
      sdpu_callback(ccb, reason);
      sdpu_release_ccb(ccb);
      return;
    } else {
      L2CA_DisconnectReq(p_ccb->connection_id);
      L2CA_DisconnectReq(ccb.connection_id);
    }
  }

  /* If at setup state, we may not get callback ind from L2CAP */
  /* Call user callback immediately */
  if (p_ccb->con_state == SDP_STATE_CONN_SETUP) {
    sdpu_callback(p_ccb, reason);
    sdpu_release_ccb(p_ccb);
  if (ccb.con_state == SDP_STATE_CONN_SETUP) {
    sdpu_callback(ccb, reason);
    sdpu_release_ccb(ccb);
  }
}

@@ -422,12 +424,13 @@ static void sdp_disconnect_cfm(uint16_t l2cap_cid,
                      l2cap_cid);
    return;
  }
  tCONN_CB& ccb = *p_ccb;

  SDP_TRACE_EVENT("SDP - Rcvd L2CAP disc cfm, CID: 0x%x", l2cap_cid);

  sdpu_callback(p_ccb, static_cast<tSDP_STATUS>(p_ccb->disconnect_reason));
  sdpu_process_pend_ccb(p_ccb->connection_id, false);
  sdpu_release_ccb(p_ccb);
  sdpu_callback(ccb, static_cast<tSDP_STATUS>(ccb.disconnect_reason));
  sdpu_process_pend_ccb(ccb, false);
  sdpu_release_ccb(ccb);
}

/*******************************************************************************
@@ -441,14 +444,14 @@ static void sdp_disconnect_cfm(uint16_t l2cap_cid,
 *
 ******************************************************************************/
void sdp_conn_timer_timeout(void* data) {
  tCONN_CB* p_ccb = (tCONN_CB*)data;
  tCONN_CB& ccb = *(tCONN_CB*)data;

  SDP_TRACE_EVENT("SDP - CCB timeout in state: %d  CID: 0x%x", p_ccb->con_state,
                  p_ccb->connection_id);
  SDP_TRACE_EVENT("SDP - CCB timeout in state: %d  CID: 0x%x", ccb.con_state,
                  ccb.connection_id);

  L2CA_DisconnectReq(p_ccb->connection_id);
  L2CA_DisconnectReq(ccb.connection_id);

  sdpu_callback(p_ccb, SDP_CONN_FAILED);
  sdpu_clear_pend_ccb(p_ccb->connection_id);
  sdpu_release_ccb(p_ccb);
  sdpu_callback(ccb, SDP_CONN_FAILED);
  sdpu_clear_pend_ccb(ccb);
  sdpu_release_ccb(ccb);
}
+20 −20
Original line number Diff line number Diff line
@@ -393,11 +393,11 @@ tCONN_CB* sdpu_allocate_ccb(void) {
 * Returns          void
 *
 ******************************************************************************/
void sdpu_callback(tCONN_CB* p_ccb, tSDP_REASON reason) {
  if (p_ccb->p_cb) {
    (*p_ccb->p_cb)(reason);
  } else if (p_ccb->p_cb2) {
    (*p_ccb->p_cb2)(reason, p_ccb->user_data);
void sdpu_callback(tCONN_CB& ccb, tSDP_REASON reason) {
  if (ccb.p_cb) {
    (ccb.p_cb)(reason);
  } else if (ccb.p_cb2) {
    (ccb.p_cb2)(reason, ccb.user_data);
  }
}

@@ -410,17 +410,17 @@ void sdpu_callback(tCONN_CB* p_ccb, tSDP_REASON reason) {
 * Returns          void
 *
 ******************************************************************************/
void sdpu_release_ccb(tCONN_CB* p_ccb) {
void sdpu_release_ccb(tCONN_CB& ccb) {
  /* Ensure timer is stopped */
  alarm_cancel(p_ccb->sdp_conn_timer);
  alarm_cancel(ccb.sdp_conn_timer);

  /* Drop any response pointer we may be holding */
  p_ccb->con_state = SDP_STATE_IDLE;
  p_ccb->is_attr_search = false;
  ccb.con_state = SDP_STATE_IDLE;
  ccb.is_attr_search = false;

  /* Free the response buffer */
  if (p_ccb->rsp_list) SDP_TRACE_DEBUG("releasing SDP rsp_list");
  osi_free_and_reset((void**)&p_ccb->rsp_list);
  if (ccb.rsp_list) SDP_TRACE_DEBUG("releasing SDP rsp_list");
  osi_free_and_reset((void**)&ccb.rsp_list);
}

/*******************************************************************************
@@ -468,7 +468,7 @@ uint16_t sdpu_get_active_ccb_cid(const RawAddress& remote_bd_addr) {
 * Returns          returns true if any pending ccb, else false.
 *
 ******************************************************************************/
bool sdpu_process_pend_ccb(uint16_t cid, bool use_cur_chnl) {
bool sdpu_process_pend_ccb(tCONN_CB& ccb, bool use_cur_chnl) {
  uint16_t xx;
  tCONN_CB* p_ccb;

@@ -476,7 +476,7 @@ bool sdpu_process_pend_ccb(uint16_t cid, bool use_cur_chnl) {
    // Look through each connection control block for active sdp on given remote
    for (xx = 0, p_ccb = sdp_cb.ccb; xx < SDP_MAX_CONNECTIONS; xx++, p_ccb++) {
      if ((p_ccb->con_state == SDP_STATE_CONN_PEND) &&
          (p_ccb->connection_id == cid) &&
          (p_ccb->connection_id == ccb.connection_id) &&
          (p_ccb->con_flags & SDP_FLAGS_IS_ORIG)) {
        p_ccb->con_state = SDP_STATE_CONNECTED;
        sdp_disc_connected(p_ccb);
@@ -491,7 +491,7 @@ bool sdpu_process_pend_ccb(uint16_t cid, bool use_cur_chnl) {
  bool new_conn = false;
  for (xx = 0, p_ccb = sdp_cb.ccb; xx < SDP_MAX_CONNECTIONS; xx++, p_ccb++) {
    if ((p_ccb->con_state == SDP_STATE_CONN_PEND) &&
        (p_ccb->connection_id == cid) &&
        (p_ccb->connection_id == ccb.connection_id) &&
        (p_ccb->con_flags & SDP_FLAGS_IS_ORIG)) {
      if (!new_conn) {
        p_ccb->con_state = SDP_STATE_CONN_SETUP;
@@ -503,8 +503,8 @@ bool sdpu_process_pend_ccb(uint16_t cid, bool use_cur_chnl) {
      if (new_cid != 0) {
        p_ccb->connection_id = new_cid;
      } else {
        sdpu_callback(p_ccb, SDP_CONN_FAILED);
        sdpu_release_ccb(p_ccb);
        sdpu_callback(*p_ccb, SDP_CONN_FAILED);
        sdpu_release_ccb(*p_ccb);
      }
    }
  }
@@ -522,17 +522,17 @@ bool sdpu_process_pend_ccb(uint16_t cid, bool use_cur_chnl) {
 * Returns          returns none.
 *
 ******************************************************************************/
void sdpu_clear_pend_ccb(uint16_t cid) {
void sdpu_clear_pend_ccb(tCONN_CB& ccb) {
  uint16_t xx;
  tCONN_CB* p_ccb;

  // Look through each connection control block for active sdp on given remote
  for (xx = 0, p_ccb = sdp_cb.ccb; xx < SDP_MAX_CONNECTIONS; xx++, p_ccb++) {
    if ((p_ccb->con_state == SDP_STATE_CONN_PEND) &&
        (p_ccb->connection_id == cid) &&
        (p_ccb->connection_id == ccb.connection_id) &&
        (p_ccb->con_flags & SDP_FLAGS_IS_ORIG)) {
      sdpu_callback(p_ccb, SDP_CONN_FAILED);
      sdpu_release_ccb(p_ccb);
      sdpu_callback(*p_ccb, SDP_CONN_FAILED);
      sdpu_release_ccb(*p_ccb);
    }
  }
  return;
+9 −6
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ typedef struct {
} tSDP_CONT_INFO;

/* Define the SDP Connection Control Block */
typedef struct {
struct tCONN_CB {
#define SDP_STATE_IDLE 0
#define SDP_STATE_CONN_SETUP 1
#define SDP_STATE_CFG_SETUP 2
@@ -167,8 +167,11 @@ typedef struct {
  uint16_t cont_offset;     /* Continuation state data in the server response */
  tSDP_CONT_INFO cont_info; /* structure to hold continuation information for
                               the server response */
  tCONN_CB() = default;

} tCONN_CB;
 private:
  tCONN_CB(const tCONN_CB&) = delete;
};

/*  The main SDP control block */
typedef struct {
@@ -200,7 +203,7 @@ extern void sdpu_log_attribute_metrics(const RawAddress& bda,
extern tCONN_CB* sdpu_find_ccb_by_cid(uint16_t cid);
extern tCONN_CB* sdpu_find_ccb_by_db(const tSDP_DISCOVERY_DB* p_db);
extern tCONN_CB* sdpu_allocate_ccb(void);
extern void sdpu_release_ccb(tCONN_CB* p_ccb);
extern void sdpu_release_ccb(tCONN_CB& p_ccb);

extern uint8_t* sdpu_build_attrib_seq(uint8_t* p_out, uint16_t* p_attr,
                                      uint16_t num_attrs);
@@ -238,9 +241,9 @@ extern bool spdu_is_avrcp_version_valid(const uint16_t version);
extern void sdpu_set_avrc_target_version(const tSDP_ATTRIBUTE* p_attr,
                                         const RawAddress* bdaddr);
extern uint16_t sdpu_get_active_ccb_cid(const RawAddress& remote_bd_addr);
extern bool sdpu_process_pend_ccb(uint16_t cid, bool use_cur_chnl);
extern void sdpu_clear_pend_ccb(uint16_t cid);
extern void sdpu_callback(tCONN_CB* p_ccb, tSDP_REASON reason);
extern bool sdpu_process_pend_ccb(tCONN_CB& ccb, bool use_cur_chnl);
extern void sdpu_clear_pend_ccb(tCONN_CB& ccb);
extern void sdpu_callback(tCONN_CB& ccb, tSDP_REASON reason);

/* Functions provided by sdp_db.cc
 */