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

Commit 9f2aa9d2 authored by Chris Manton's avatar Chris Manton
Browse files

Re-log stack/l2cap/l2c_api::L2CA_SendFixedChnlData

Towards loggable code

Bug: 163134718
Tag: #refactor
Test: act.py -tc BleCocTest
Test: ble paired 2 phones
Test: classic paired Bose SoundLink
Change-Id: I4a18d89e6c2035df8134462ac40e6401f3274790
parent 0f26c677
Loading
Loading
Loading
Loading
+16 −24
Original line number Diff line number Diff line
@@ -1287,36 +1287,28 @@ uint16_t L2CA_SendFixedChnlData(uint16_t fixed_cid, const RawAddress& rem_bda,
  tL2C_LCB* p_lcb;
  tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR;

  VLOG(2) << __func__ << " BDA: " << rem_bda
          << StringPrintf(" CID: 0x%04x", fixed_cid);

  if (fixed_cid >= L2CAP_ATT_CID && fixed_cid <= L2CAP_SMP_CID)
    transport = BT_TRANSPORT_LE;

  // Check CID is valid and registered
  if ((fixed_cid < L2CAP_FIRST_FIXED_CHNL) ||
      (fixed_cid > L2CAP_LAST_FIXED_CHNL) ||
      (l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb ==
       NULL)) {
    L2CAP_TRACE_ERROR("L2CA_SendFixedChnlData()  Invalid CID: 0x%04x",
                      fixed_cid);
    LOG_WARN("No service registered or invalid CID: 0x%04x", fixed_cid);
    osi_free(p_buf);
    return (L2CAP_DW_FAILED);
  }

  // Fail if BT is not yet up
  if (!BTM_IsDeviceUp()) {
    L2CAP_TRACE_WARNING("L2CA_SendFixedChnlData(0x%04x) - BTU not ready",
                        fixed_cid);
    LOG_WARN("Controller is not ready CID: 0x%04x", fixed_cid);
    osi_free(p_buf);
    return (L2CAP_DW_FAILED);
  }

  // We need to have a link up
  p_lcb = l2cu_find_lcb_by_bd_addr(rem_bda, transport);
  if (p_lcb == NULL || p_lcb->link_state == LST_DISCONNECTING) {
    /* if link is disconnecting, also report data sending failure */
    L2CAP_TRACE_WARNING("L2CA_SendFixedChnlData(0x%04x) - no LCB", fixed_cid);
    LOG_WARN("Link is disconnecting or does not exist CID: 0x%04x", fixed_cid);
    osi_free(p_buf);
    return (L2CAP_DW_FAILED);
  }
@@ -1330,9 +1322,7 @@ uint16_t L2CA_SendFixedChnlData(uint16_t fixed_cid, const RawAddress& rem_bda,
    peer_channel_mask = p_lcb->peer_chnl_mask[0];

  if ((peer_channel_mask & (1 << fixed_cid)) == 0) {
    L2CAP_TRACE_WARNING(
        "L2CA_SendFixedChnlData() - peer does not support fixed chnl: 0x%04x",
        fixed_cid);
    LOG_WARN("Peer does not support fixed channel CID: 0x%04x", fixed_cid);
    osi_free(p_buf);
    return (L2CAP_DW_FAILED);
  }
@@ -1342,19 +1332,18 @@ uint16_t L2CA_SendFixedChnlData(uint16_t fixed_cid, const RawAddress& rem_bda,

  if (!p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]) {
    if (!l2cu_initialize_fixed_ccb(p_lcb, fixed_cid)) {
      L2CAP_TRACE_WARNING("L2CA_SendFixedChnlData() - no CCB for chnl: 0x%4x",
                          fixed_cid);
      LOG_WARN("No channel control block found for CID: 0x%4x", fixed_cid);
      osi_free(p_buf);
      return (L2CAP_DW_FAILED);
    }
  }

  // If already congested, do not accept any more packets
  if (p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->cong_sent) {
    L2CAP_TRACE_ERROR(
        "L2CAP - CID: 0x%04x cannot send, already congested \
            xmit_hold_q.count: %u buff_quota: %u",
        fixed_cid, fixed_queue_length(
    LOG_WARN(
        "Unable to send data due to congestion CID: 0x%04x xmit_hold_q.count: "
        "%zu buff_quota: %u",
        fixed_cid,
        fixed_queue_length(
            p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]
                ->xmit_hold_q),
        p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->buff_quota);
@@ -1362,6 +1351,7 @@ uint16_t L2CA_SendFixedChnlData(uint16_t fixed_cid, const RawAddress& rem_bda,
    return (L2CAP_DW_FAILED);
  }

  LOG_DEBUG("Enqueued data for CID: 0x%04x len:%hu", fixed_cid, p_buf->len);
  l2c_enqueue_peer_data(p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL],
                        p_buf);

@@ -1374,8 +1364,10 @@ uint16_t L2CA_SendFixedChnlData(uint16_t fixed_cid, const RawAddress& rem_bda,
    l2cu_no_dynamic_ccbs(p_lcb);
  }

  if (p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->cong_sent)
  if (p_lcb->p_fixed_ccbs[fixed_cid - L2CAP_FIRST_FIXED_CHNL]->cong_sent) {
    LOG_DEBUG("Link congested for CID: 0x%04x", fixed_cid);
    return (L2CAP_DW_CONGESTED);
  }

  return (L2CAP_DW_SUCCESS);
}