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

Commit be9b9f12 authored by Chris Manton's avatar Chris Manton
Browse files

stack::l2cap: Remove duplicated API get_remote_cid

prefer L2CA_GetRemoteChannelId over L2CA_GetRemoteCid,L2CA_GetPeerChannelId

Bug: 345276607
Test: m .
Flag: EXEMPT, Mechanical Refactor
Change-Id: I692cf4792631d0b81f4ce8aa57fcb441d7a71628
parent 69a9e8a3
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -3153,7 +3153,7 @@ void bta_av_vendor_offload_start_v2(tBTA_AV_SCB* p_scb,
  if (mtu > MAX_3MBPS_AVDTP_MTU) {
    mtu = MAX_3MBPS_AVDTP_MTU;
  }
  if (L2CA_GetRemoteCid(p_scb->l2c_cid, &l2cap_channel_handle) == false) {
  if (L2CA_GetRemoteChannelId(p_scb->l2c_cid, &l2cap_channel_handle) == false) {
    log::error("Failed to fetch l2c rcid");
  }

@@ -3208,7 +3208,8 @@ void bta_av_vendor_offload_stop() {
            p_scb->PeerAddress(), BT_TRANSPORT_BR_EDR);
    uint16_t l2cap_channel_handle = 0;

    if (L2CA_GetRemoteCid(p_scb->l2c_cid, &l2cap_channel_handle) == false) {
    if (L2CA_GetRemoteChannelId(p_scb->l2c_cid, &l2cap_channel_handle) ==
        false) {
      log::error("Failed to fetch l2c rcid");
    }

@@ -3399,7 +3400,8 @@ static void bta_av_offload_codec_builder(tBTA_AV_SCB* p_scb,
      p_a2dp_offload->sample_rate = BTAV_A2DP_CODEC_SAMPLE_RATE_96000;
      break;
  }
  if (L2CA_GetRemoteCid(p_scb->l2c_cid, &p_a2dp_offload->l2c_rcid) == false) {
  if (L2CA_GetRemoteChannelId(p_scb->l2c_cid, &p_a2dp_offload->l2c_rcid) ==
      false) {
    log::error("Failed to fetch l2c rcid");
    return;
  }
+0 −6
Original line number Diff line number Diff line
@@ -226,12 +226,6 @@ uint8_t L2CA_DataWrite(uint16_t cid, BT_HDR* p_data);

uint8_t L2CA_LECocDataWrite(uint16_t cid, BT_HDR* p_data);

// Given a local channel identifier, |lcid|, this function returns the bound
// remote channel identifier, |rcid|. If
// |lcid| is not known or is invalid, this function returns false and does not
// modify the value pointed at by |rcid|. |rcid| may be NULL.
bool L2CA_GetRemoteCid(uint16_t lcid, uint16_t* rcid);

/*******************************************************************************
 *
 * Function         L2CA_SetIdleTimeoutByBdAddr
+1 −1
Original line number Diff line number Diff line
@@ -660,7 +660,7 @@ static void gap_checks_con_flags(tGAP_CCB* p_ccb) {
    tGAP_CB_DATA cb_data;
    uint16_t l2cap_remote_cid;
    if (com::android::bluetooth::flags::bt_socket_api_l2cap_cid() &&
        L2CA_GetPeerChannelId(p_ccb->connection_id, &l2cap_remote_cid)) {
        L2CA_GetRemoteChannelId(p_ccb->connection_id, &l2cap_remote_cid)) {
      cb_data.l2cap_cids.local_cid = p_ccb->connection_id;
      cb_data.l2cap_cids.remote_cid = l2cap_remote_cid;
      cb_data_ptr = &cb_data;
+16 −19
Original line number Diff line number Diff line
@@ -586,11 +586,22 @@ void L2CA_DeregisterLECoc(uint16_t psm);

[[nodiscard]] uint8_t L2CA_LECocDataWrite(uint16_t cid, BT_HDR* p_data);

// Given a local channel identifier, |lcid|, this function returns the bound
// remote channel identifier, |rcid|. If
// |lcid| is not known or is invalid, this function returns false and does not
// modify the value pointed at by |rcid|. |rcid| may be NULL.
[[nodiscard]] bool L2CA_GetRemoteCid(uint16_t lcid, uint16_t* rcid);
/*******************************************************************************
 *
 *  Function        L2CA_GetRemoteChannelId
 *
 *  Description     Given a local channel identifier, |lcid|, this function
 *                  returns the bound remote channel identifier, |rcid|. If
 *                  |lcid| is not known or is invalid, this function returns
 *                  false and does not modify the value pointed at by |rcid|.
 *
 *  Parameters:     lcid: Local CID
 *                  rcid: Pointer to remote CID must NOT be nullptr
 *
 *  Return value:   true if rcid lookup was successful
 *
 ******************************************************************************/
[[nodiscard]] bool L2CA_GetRemoteChannelId(uint16_t lcid, uint16_t* rcid);

/*******************************************************************************
 *
@@ -946,20 +957,6 @@ void L2CA_SetMediaStreamChannel(uint16_t local_media_cid, bool status);
[[nodiscard]] bool L2CA_isMediaChannel(uint16_t handle, uint16_t channel_id,
                                       bool is_local_cid);

/*******************************************************************************
 *
 *  Function        L2CA_GetPeerChannelId
 *
 *  Description     Get remote channel ID for Connection Oriented Channel.
 *
 *  Parameters:     lcid: Local CID
 *                  rcid: Pointer to remote CID
 *
 *  Return value:   true if peer is connected
 *
 ******************************************************************************/
[[nodiscard]] bool L2CA_GetPeerChannelId(uint16_t lcid, uint16_t* rcid);

namespace fmt {
template <>
struct formatter<tL2CAP_LATENCY> : enum_formatter<tL2CAP_LATENCY> {};
+21 −30
Original line number Diff line number Diff line
@@ -931,12 +931,29 @@ bool L2CA_DisconnectReq(uint16_t cid) {

bool L2CA_DisconnectLECocReq(uint16_t cid) { return L2CA_DisconnectReq(cid); }

bool L2CA_GetRemoteCid(uint16_t lcid, uint16_t* rcid) {
  tL2C_CCB* control_block = l2cu_find_ccb_by_cid(NULL, lcid);
  if (!control_block) return false;
/*******************************************************************************
 *
 *  Function        L2CA_GetRemoteChannelId
 *
 *  Description     Get remote channel ID for Connection Oriented Channel.
 *
 *  Parameters:     lcid: Local CID
 *                  rcid: Pointer to remote CID
 *
 *  Return value:   true if peer is connected
 *
 ******************************************************************************/
bool L2CA_GetRemoteChannelId(uint16_t lcid, uint16_t* rcid) {
  log::assert_that(rcid != nullptr, "assert failed: rcid != nullptr");

  if (rcid) *rcid = control_block->remote_cid;
  log::verbose("LCID: 0x{:04x}", lcid);
  tL2C_CCB* p_ccb = l2cu_find_ccb_by_cid(nullptr, lcid);
  if (p_ccb == nullptr) {
    log::error("No CCB for CID:0x{:04x}", lcid);
    return false;
  }

  *rcid = p_ccb->remote_cid;
  return true;
}

@@ -1758,32 +1775,6 @@ bool L2CA_isMediaChannel(uint16_t handle, uint16_t channel_id,
  return ret;
}

/*******************************************************************************
 *
 *  Function        L2CA_GetPeerChannelId
 *
 *  Description     Get remote channel ID for Connection Oriented Channel.
 *
 *  Parameters:     lcid: Local CID
 *                  rcid: Pointer to remote CID
 *
 *  Return value:   true if peer is connected
 *
 ******************************************************************************/
bool L2CA_GetPeerChannelId(uint16_t lcid, uint16_t* rcid) {
  log::verbose("CID: 0x{:04x}", lcid);

  tL2C_CCB* p_ccb = l2cu_find_ccb_by_cid(nullptr, lcid);
  if (p_ccb == nullptr) {
    log::error("No CCB for CID:0x{:04x}", lcid);
    return false;
  }

  log::assert_that(rcid != nullptr, "assert failed: rcid != nullptr");
  *rcid = p_ccb->remote_cid;
  return true;
}

using namespace bluetooth;

#define DUMPSYS_TAG "shim::legacy::l2cap"
Loading