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

Commit 5a2a1ce5 authored by Chris Manton's avatar Chris Manton
Browse files

[22/25] stack::sdp Use stack::l2cap::get_interface()

Bug: 343808590
Test: m .
Flag: EXEMPT, Mechanical Refactor

Change-Id: I24d81356f5145aad0166c3e45ca4262bc642d54b
parent 5623e6cc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -75,7 +75,7 @@ public:
            [](uint16_t psm, const RawAddress& raw_address) { return kDummyCID; };
    test::mock::stack_l2cap_api::L2CA_ConnectReqWithSecurity.body =
            [](uint16_t psm, const RawAddress& p_bd_addr, uint16_t sec_level) {
              return L2CA_ConnectReq(psm, p_bd_addr);
              return bluetooth::stack::l2cap::get_interface().L2CA_ConnectReq(psm, p_bd_addr);
            };
    test::mock::stack_l2cap_api::L2CA_DataWrite.body = [](uint16_t cid,
                                                          BT_HDR* p_data) -> tL2CAP_DW_RESULT {
+6 −3
Original line number Diff line number Diff line
@@ -176,7 +176,8 @@ static void sdp_snd_service_search_req(tCONN_CB* p_ccb, uint8_t cont_len, uint8_
  /* Set the length of the SDP data in the buffer */
  p_cmd->len = (uint16_t)(p - p_start);

  if (L2CA_DataWrite(p_ccb->connection_id, p_cmd) != tL2CAP_DW_RESULT::SUCCESS) {
  if (stack::l2cap::get_interface().L2CA_DataWrite(p_ccb->connection_id, p_cmd) !=
      tL2CAP_DW_RESULT::SUCCESS) {
    log::warn("Unable to write L2CAP data peer:{} cid:{} len:{}", p_ccb->device_address,
              p_ccb->connection_id, p_cmd->len);
  }
@@ -693,7 +694,8 @@ static void process_service_search_attr_rsp(tCONN_CB* p_ccb, uint8_t* p_reply,
    /* Set the length of the SDP data in the buffer */
    p_msg->len = p - p_start;

    if (L2CA_DataWrite(p_ccb->connection_id, p_msg) != tL2CAP_DW_RESULT::SUCCESS) {
    if (stack::l2cap::get_interface().L2CA_DataWrite(p_ccb->connection_id, p_msg) !=
        tL2CAP_DW_RESULT::SUCCESS) {
      log::warn("Unable to write L2CAP data peer:{} cid:{} len:{}", p_ccb->device_address,
                p_ccb->connection_id, p_msg->len);
    }
@@ -861,7 +863,8 @@ static void process_service_attr_rsp(tCONN_CB* p_ccb, uint8_t* p_reply, uint8_t*
    /* Set the length of the SDP data in the buffer */
    p_msg->len = (uint16_t)(p - p_start);

    if (L2CA_DataWrite(p_ccb->connection_id, p_msg) != tL2CAP_DW_RESULT::SUCCESS) {
    if (stack::l2cap::get_interface().L2CA_DataWrite(p_ccb->connection_id, p_msg) !=
        tL2CAP_DW_RESULT::SUCCESS) {
      log::warn("Unable to write L2CAP data peer:{} cid:{} len:{}", p_ccb->device_address,
                p_ccb->connection_id, p_msg->len);
    }
+8 −7
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@
#include "stack/include/bt_hdr.h"
#include "stack/include/bt_psm_types.h"
#include "stack/include/btm_sec_api_types.h"
#include "stack/include/l2c_api.h"
#include "stack/include/l2cdefs.h"
#include "stack/include/sdp_status.h"
#include "stack/sdp/sdpint.h"
@@ -286,7 +285,8 @@ tCONN_CB* sdp_conn_originate(const RawAddress& bd_addr) {
  /* Transition to the next appropriate state, waiting for connection confirm */
  if (cid == 0) {
    p_ccb->con_state = tSDP_STATE::CONN_SETUP;
    cid = L2CA_ConnectReqWithSecurity(BT_PSM_SDP, bd_addr, BTM_SEC_NONE);
    cid = stack::l2cap::get_interface().L2CA_ConnectReqWithSecurity(BT_PSM_SDP, bd_addr,
                                                                    BTM_SEC_NONE);
  } else {
    p_ccb->con_state = tSDP_STATE::CONN_PEND;
    log::warn("SDP already active for peer {}. cid={:#0x}", bd_addr, cid);
@@ -323,7 +323,7 @@ void sdp_disconnect(tCONN_CB* p_ccb, tSDP_REASON reason) {
      sdpu_release_ccb(ccb);
      return;
    } else {
      if (!L2CA_DisconnectReq(ccb.connection_id)) {
      if (!stack::l2cap::get_interface().L2CA_DisconnectReq(ccb.connection_id)) {
        log::warn("Unable to disconnect L2CAP peer:{} cid:{}", ccb.device_address,
                  ccb.connection_id);
      }
@@ -381,7 +381,7 @@ void sdp_conn_timer_timeout(void* data) {
  log::verbose("SDP - CCB timeout in state: {}  CID: 0x{:x}", sdp_state_text(ccb.con_state),
               ccb.connection_id);

  if (!L2CA_DisconnectReq(ccb.connection_id)) {
  if (!stack::l2cap::get_interface().L2CA_DisconnectReq(ccb.connection_id)) {
    log::warn("Unable to disconnect L2CAP peer:{} cid:{}", ccb.device_address, ccb.connection_id);
  }

@@ -424,14 +424,15 @@ void sdp_init(void) {
  sdp_cb.reg_info.pL2CA_Error_Cb = sdp_on_l2cap_error;

  /* Now, register with L2CAP */
  if (!L2CA_RegisterWithSecurity(BT_PSM_SDP, sdp_cb.reg_info, true /* enable_snoop */, nullptr,
  if (!stack::l2cap::get_interface().L2CA_RegisterWithSecurity(BT_PSM_SDP, sdp_cb.reg_info,
                                                               true /* enable_snoop */, nullptr,
                                                               SDP_MTU_SIZE, 0, BTM_SEC_NONE)) {
    log::error("SDP Registration failed");
  }
}

void sdp_free(void) {
  L2CA_Deregister(BT_PSM_SDP);
  stack::l2cap::get_interface().L2CA_Deregister(BT_PSM_SDP);
  for (int i = 0; i < SDP_MAX_CONNECTIONS; i++) {
    alarm_free(sdp_cb.ccb[i].sdp_conn_timer);
    sdp_cb.ccb[i].sdp_conn_timer = NULL;
+6 −3
Original line number Diff line number Diff line
@@ -297,7 +297,8 @@ static void process_service_search(tCONN_CB* p_ccb, uint16_t trans_num, uint16_t
  p_buf->len = p_rsp - p_rsp_start;

  /* Send the buffer through L2CAP */
  if (L2CA_DataWrite(p_ccb->connection_id, p_buf) != tL2CAP_DW_RESULT::SUCCESS) {
  if (stack::l2cap::get_interface().L2CA_DataWrite(p_ccb->connection_id, p_buf) !=
      tL2CAP_DW_RESULT::SUCCESS) {
    log::warn("Unable to write L2CAP data peer:{} cid:{} len:{}", p_ccb->device_address,
              p_ccb->connection_id, p_buf->len);
  }
@@ -560,7 +561,8 @@ static void process_service_attr_req(tCONN_CB* p_ccb, uint16_t trans_num, uint16
  p_buf->len = p_rsp - p_rsp_start;

  /* Send the buffer through L2CAP */
  if (L2CA_DataWrite(p_ccb->connection_id, p_buf) != tL2CAP_DW_RESULT::SUCCESS) {
  if (stack::l2cap::get_interface().L2CA_DataWrite(p_ccb->connection_id, p_buf) !=
      tL2CAP_DW_RESULT::SUCCESS) {
    log::warn("Unable to write L2CAP data peer:{} cid:{} len:{}", p_ccb->device_address,
              p_ccb->connection_id, p_buf->len);
  }
@@ -916,7 +918,8 @@ static void process_service_search_attr_req(tCONN_CB* p_ccb, uint16_t trans_num,
  p_buf->len = p_rsp - p_rsp_start;

  /* Send the buffer through L2CAP */
  if (L2CA_DataWrite(p_ccb->connection_id, p_buf) != tL2CAP_DW_RESULT::SUCCESS) {
  if (stack::l2cap::get_interface().L2CA_DataWrite(p_ccb->connection_id, p_buf) !=
      tL2CAP_DW_RESULT::SUCCESS) {
    log::warn("Unable to write L2CAP data peer:{} cid:{} len:{}", p_ccb->device_address,
              p_ccb->connection_id, p_buf->len);
  }
+13 −6
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@
#include "stack/include/bt_types.h"
#include "stack/include/bt_uuid16.h"
#include "stack/include/btm_sec_api_types.h"
#include "stack/include/l2cap_interface.h"
#include "stack/include/sdpdefs.h"
#include "stack/include/stack_metrics_logging.h"
#include "stack/sdp/internal/sdp_api.h"
@@ -522,7 +523,8 @@ bool sdpu_process_pend_ccb_new_cid(const tCONN_CB& ccb) {
      if (!new_conn) {
        // Only change state of the first ccb
        p_ccb->con_state = tSDP_STATE::CONN_SETUP;
        new_cid = L2CA_ConnectReqWithSecurity(BT_PSM_SDP, p_ccb->device_address, BTM_SEC_NONE);
        new_cid = stack::l2cap::get_interface().L2CA_ConnectReqWithSecurity(
                BT_PSM_SDP, p_ccb->device_address, BTM_SEC_NONE);
        new_conn = true;
      }
      // Check if L2CAP started the connection process
@@ -732,7 +734,8 @@ void sdpu_build_n_send_error(tCONN_CB* p_ccb, uint16_t trans_num, tSDP_STATUS er
  p_buf->len = p_rsp - p_rsp_start;

  /* Send the buffer through L2CAP */
  if (L2CA_DataWrite(p_ccb->connection_id, p_buf) != tL2CAP_DW_RESULT::SUCCESS) {
  if (stack::l2cap::get_interface().L2CA_DataWrite(p_ccb->connection_id, p_buf) !=
      tL2CAP_DW_RESULT::SUCCESS) {
    log::warn("Unable to write L2CAP data cid:{}", p_ccb->connection_id);
  }
}
@@ -1536,7 +1539,9 @@ void sdpu_set_avrc_target_version(const tSDP_ATTRIBUTE* p_attr, const RawAddress
  }

  if (iop_version != 0) {
    log::info("device={} is in IOP database. Reply AVRC Target version {:x} instead of {:x}.",
    log::info(
            "device={} is in IOP database. Reply AVRC Target version {:x} instead "
            "of {:x}.",
            *bdaddr, iop_version, avrcp_version);
    uint8_t* p_version = p_attr->value_ptr + 6;
    UINT16_TO_BE_FIELD(p_version, iop_version);
@@ -1638,7 +1643,9 @@ void sdpu_set_avrc_target_features(const tSDP_ATTRIBUTE* p_attr, const RawAddres
  bool browsing_supported = ((AVRCP_FEAT_BRW_BIT & avrcp_peer_features) == AVRCP_FEAT_BRW_BIT);
  bool coverart_supported = ((AVRCP_FEAT_CA_BIT & avrcp_peer_features) == AVRCP_FEAT_CA_BIT);

  log::info("SDP AVRCP DB Version 0x{:x}, browse supported {}, cover art supported {}",
  log::info(
          "SDP AVRCP DB Version 0x{:x}, browse supported {}, cover art supported "
          "{}",
          avrcp_peer_features, browsing_supported, coverart_supported);
  if (avrcp_version < AVRC_REV_1_4 || !browsing_supported) {
    log::info("Reset Browsing Feature");
Loading