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

Commit 8f9499d0 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

l2c: Change std::vector to uint16[] in the tL2C_LCB

Since there are places where memset is done on tL2C_LCB
we can't keep std::vector in this struct

Tag: #feature
Bug: 159786353
Sponsor: jpawlowski@
Test: compile & manual

Change-Id: I2a9795e3c7dbe280b17725eac6333744440e89df
parent 985bca4b
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -833,7 +833,10 @@ std::vector<uint16_t> L2CA_ConnectCreditBasedReq(uint16_t psm,
    allocated_cids.push_back(p_ccb->local_cid);
  }

  p_lcb->pending_ecoc_connection_cids = allocated_cids;
  for (int i = 0; i < (int)(allocated_cids.size()); i++)
    p_lcb->pending_ecoc_connection_cids[i] = allocated_cids[i];

  p_lcb->pending_ecoc_conn_cnt = (uint16_t)(allocated_cids.size());
  l2c_csm_execute(p_ccb_primary, L2CEVT_L2CA_CREDIT_BASED_CONNECT_REQ, NULL);

  L2CAP_TRACE_API("%s(psm: 0x%04x) returned CID: 0x%04x", __func__, psm,
+17 −15
Original line number Diff line number Diff line
@@ -574,7 +574,7 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) {
          "num_of_channels = %d",
          mtu, mps, initial_credit, num_of_channels);

      if (p_lcb->pending_ecoc_connection_cids.size() > 0) {
      if (p_lcb->pending_ecoc_conn_cnt > 0) {
        L2CAP_TRACE_WARNING(
            "L2CAP - L2CAP_CMD_CREDIT_BASED_CONN_REQ collision:");
        l2cu_reject_credit_based_conn_req(p_lcb, id, num_of_channels,
@@ -582,6 +582,8 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) {
        return;
      }

      p_lcb->pending_ecoc_conn_cnt = num_of_channels;

      /* Check PSM Support */
      p_rcb = l2cu_find_ble_rcb_by_psm(con_info.psm);
      if (p_rcb == NULL) {
@@ -610,8 +612,7 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) {
        return;
      }

      /* Clear previous list */
      p_lcb->pending_ecoc_allocated_cids.clear();
      bool lead_cid_set = false;

      for (int i = 0; i < num_of_channels; i++) {
        STREAM_TO_UINT16(rcid, p);
@@ -619,7 +620,7 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) {
        if (temp_p_ccb) {
          L2CAP_TRACE_WARNING(
              "L2CAP - rcvd conn req for duplicated cid: 0x%04x", rcid);
          p_lcb->pending_ecoc_connection_cids.push_back(0);
          p_lcb->pending_ecoc_connection_cids[i] = 0;
          p_lcb->pending_l2cap_result =
              L2CAP_LE_RESULT_SOURCE_CID_ALREADY_ALLOCATED;
        } else {
@@ -627,7 +628,7 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) {
          temp_p_ccb = l2cu_allocate_ccb(p_lcb, 0);
          if (temp_p_ccb == NULL) {
            L2CAP_TRACE_ERROR("L2CAP - unable to allocate CCB");
            p_lcb->pending_ecoc_connection_cids.push_back(0);
            p_lcb->pending_ecoc_connection_cids[i] = 0;
            p_lcb->pending_l2cap_result = L2CAP_LE_RESULT_NO_RESOURCES;
            continue;
          }
@@ -648,20 +649,18 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) {
          temp_p_ccb->peer_cfg.fcr.mode = L2CAP_FCR_LE_COC_MODE;

          /* This list will be used to prepare response */
          p_lcb->pending_ecoc_connection_cids.push_back(temp_p_ccb->local_cid);

          /* This is used to notify user */
          p_lcb->pending_ecoc_allocated_cids.push_back(temp_p_ccb->local_cid);
          p_lcb->pending_ecoc_connection_cids[i] = temp_p_ccb->local_cid;

          /*This is going to be our lead p_ccb for state machine */
          if (p_lcb->pending_ecoc_allocated_cids.size() == 1) {
          if (!lead_cid_set) {
            p_ccb = temp_p_ccb;
            p_lcb->pending_lead_cid = p_ccb->local_cid;
            lead_cid_set = true;
          }
        }
      }

      if (p_lcb->pending_ecoc_allocated_cids.size() == 0) {
      if (!lead_cid_set) {
        L2CAP_TRACE_ERROR("L2CAP - unable to allocate CCB");
        l2cu_reject_credit_based_conn_req(p_lcb, id, num_of_channels,
                                          p_lcb->pending_l2cap_result);
@@ -727,12 +726,12 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) {
      /* At least some of the channels has been created and parameters are
       * good*/
      num_of_channels = (p_pkt_end - p) / sizeof(uint16_t);
      if (num_of_channels != p_lcb->pending_ecoc_connection_cids.size()) {
      if (num_of_channels != p_lcb->pending_ecoc_conn_cnt) {
        L2CAP_TRACE_ERROR(
            "Incorrect response."
            "expected num of channels = %d",
            "received num of channels = %d", num_of_channels,
            p_lcb->pending_ecoc_connection_cids.size());
            p_lcb->pending_ecoc_conn_cnt);
        return;
      }

@@ -746,7 +745,8 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) {

      con_info.peer_mtu = mtu;

      for (uint16_t cid : p_lcb->pending_ecoc_connection_cids) {
      for (int i = 0; i < p_lcb->pending_ecoc_conn_cnt; i++) {
        uint16_t cid = p_lcb->pending_ecoc_connection_cids[i];
        temp_p_ccb = l2cu_find_ccb_by_cid(p_lcb, cid);
        STREAM_TO_UINT16(temp_p_ccb->remote_cid, p);

@@ -776,7 +776,9 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) {
        }
      }

      p_lcb->pending_ecoc_connection_cids.clear();
      p_lcb->pending_ecoc_conn_cnt = 0;
      memset(p_lcb->pending_ecoc_connection_cids, 0,
             L2CAP_CREDIT_BASED_MAX_CIDS);

      break;
    case L2CAP_CMD_CREDIT_BASED_RECONFIG_REQ: {
+26 −10
Original line number Diff line number Diff line
@@ -469,12 +469,17 @@ static void l2c_csm_term_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event,
          l2c_csm_send_config_req(p_ccb);
        } else {
          if (p_ccb->ecoc) {
            LOG_DEBUG("Calling CreditBasedConnect_Ind_Cb(), num of cids: %zu",
                      p_ccb->p_lcb->pending_ecoc_connection_cids.size());
            LOG_DEBUG("Calling CreditBasedConnect_Ind_Cb(), num of cids: %d",
                      p_ccb->p_lcb->pending_ecoc_conn_cnt);

            std::vector<uint16_t> pending_cids;
            for (int i = 0; i < p_ccb->p_lcb->pending_ecoc_conn_cnt; i++) {
              uint16_t cid = p_ccb->p_lcb->pending_ecoc_connection_cids[i];
              if (cid != 0) pending_cids.push_back(cid);
            }

            (*p_ccb->p_rcb->api.pL2CA_CreditBasedConnectInd_Cb)(
                p_ccb->p_lcb->remote_bd_addr,
                p_ccb->p_lcb->pending_ecoc_connection_cids, p_ccb->p_rcb->psm,
                p_ccb->p_lcb->remote_bd_addr, pending_cids, p_ccb->p_rcb->psm,
                p_ccb->peer_cfg.mtu, p_ccb->remote_id);
          } else {
            LOG_DEBUG("Calling Connect_Ind_Cb(), CID: 0x%04x",
@@ -647,14 +652,17 @@ static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, uint16_t event,
      LOG(WARNING) << __func__ << ": L2CAP connection timeout";

      if (p_ccb->ecoc) {
        for (uint16_t cid : p_lcb->pending_ecoc_connection_cids) {
        for (int i = 0; i < p_lcb->pending_ecoc_conn_cnt; i++) {
          uint16_t cid = p_lcb->pending_ecoc_connection_cids[i];
          tL2C_CCB* temp_p_ccb = l2cu_find_ccb_by_cid(p_lcb, cid);
          LOG(WARNING) << __func__ << ": lcid= " << loghex(cid);
          (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(p_ccb->local_cid,
                                              L2CAP_CONN_TIMEOUT);
          l2cu_release_ccb(temp_p_ccb);
        }
        p_lcb->pending_ecoc_connection_cids.clear();
        p_lcb->pending_ecoc_conn_cnt = 0;
        memset(p_lcb->pending_ecoc_connection_cids, 0,
               L2CAP_CREDIT_BASED_MAX_CIDS);

      } else {
        LOG(WARNING) << __func__ << ": lcid= " << loghex(p_ccb->local_cid);
@@ -734,7 +742,8 @@ static void l2c_csm_w4_l2ca_connect_rsp(tL2C_CCB* p_ccb, uint16_t event,
                                           p_ci->l2cap_result);
      alarm_cancel(p_ccb->l2c_ccb_timer);

      for (uint16_t cid : p_ccb->p_lcb->pending_ecoc_connection_cids) {
      for (int i = 0; i < p_ccb->p_lcb->pending_ecoc_conn_cnt; i++) {
        uint16_t cid = p_ccb->p_lcb->pending_ecoc_connection_cids[i];
        tL2C_CCB* temp_p_ccb = l2cu_find_ccb_by_cid(p_ccb->p_lcb, cid);
        auto it = std::find(p_ci->lcids.begin(), p_ci->lcids.end(), cid);
        if (it != p_ci->lcids.end()) {
@@ -743,7 +752,9 @@ static void l2c_csm_w4_l2ca_connect_rsp(tL2C_CCB* p_ccb, uint16_t event,
          l2cu_release_ccb(temp_p_ccb);
        }
      }
      p_ccb->p_lcb->pending_ecoc_connection_cids.clear();
      p_ccb->p_lcb->pending_ecoc_conn_cnt = 0;
      memset(p_ccb->p_lcb->pending_ecoc_connection_cids, 0,
             L2CAP_CREDIT_BASED_MAX_CIDS);

      break;
    case L2CEVT_L2CA_CONNECT_RSP:
@@ -786,11 +797,16 @@ static void l2c_csm_w4_l2ca_connect_rsp(tL2C_CCB* p_ccb, uint16_t event,
                                             p_ci->l2cap_result);
      }
      alarm_cancel(p_ccb->l2c_ccb_timer);
      for (uint16_t cid : p_ccb->p_lcb->pending_ecoc_connection_cids) {
      for (int i = 0; i < p_ccb->p_lcb->pending_ecoc_conn_cnt; i++) {
        uint16_t cid = p_ccb->p_lcb->pending_ecoc_connection_cids[i];
        tL2C_CCB* temp_p_ccb = l2cu_find_ccb_by_cid(p_ccb->p_lcb, cid);
        l2cu_release_ccb(temp_p_ccb);
      }
      p_ccb->p_lcb->pending_ecoc_connection_cids.clear();

      p_ccb->p_lcb->pending_ecoc_conn_cnt = 0;
      memset(p_ccb->p_lcb->pending_ecoc_connection_cids, 0,
             L2CAP_CREDIT_BASED_MAX_CIDS);

      break;
    case L2CEVT_L2CA_CONNECT_RSP_NEG:
      p_ci = (tL2C_CONN_INFO*)p_data;
+5 −3
Original line number Diff line number Diff line
@@ -326,6 +326,8 @@ typedef struct {
#define L2CAP_GET_PRIORITY_QUOTA(pri) \
  ((L2CAP_NUM_CHNL_PRIORITY - (pri)) * L2CAP_CHNL_PRIORITY_WEIGHT)

#define L2CAP_CREDIT_BASED_MAX_CIDS 5

/* CCBs within the same LCB are served in round robin with priority It will make
 * sure that low priority channel (for example, HF signaling on RFCOMM) can be
 * sent to the headset even if higher priority channel (for example, AV media
@@ -463,9 +465,9 @@ typedef struct t_l2c_linkcb {
  /* This is to keep list of local cids use in the
   * credit based connection response.
   */
  std::vector<uint16_t> pending_ecoc_connection_cids;
  /* List of allocated cids, sent to user for acceptance */
  std::vector<uint16_t> pending_ecoc_allocated_cids;
  uint16_t pending_ecoc_connection_cids[L2CAP_CREDIT_BASED_MAX_CIDS];
  uint8_t pending_ecoc_conn_cnt;

  uint16_t pending_lead_cid;
  uint16_t pending_l2cap_result;
} tL2C_LCB;
+8 −7
Original line number Diff line number Diff line
@@ -2734,7 +2734,7 @@ void l2cu_send_peer_credit_based_conn_req(tL2C_CCB* p_ccb) {

  p_buf = l2cu_build_header(p_lcb,
                            L2CAP_CMD_CREDIT_BASED_CONN_REQ_MIN_LEN +
                                2 * p_lcb->pending_ecoc_connection_cids.size(),
                                2 * p_lcb->pending_ecoc_conn_cnt,
                            L2CAP_CMD_CREDIT_BASED_CONN_REQ, p_ccb->local_id);
  if (p_buf == NULL) {
    L2CAP_TRACE_WARNING("%s - no buffer", __func__);
@@ -2751,14 +2751,15 @@ void l2cu_send_peer_credit_based_conn_req(tL2C_CCB* p_ccb) {
  L2CAP_TRACE_DEBUG(
      "%s PSM:0x%04x mtu:%d mps:%d initial_credit:%d, cids_cnt %d", __func__,
      p_ccb->p_rcb->real_psm, mtu, mps, initial_credit,
      p_lcb->pending_ecoc_connection_cids.size());
      p_lcb->pending_ecoc_conn_cnt);

  UINT16_TO_STREAM(p, p_ccb->p_rcb->real_psm);
  UINT16_TO_STREAM(p, mtu);
  UINT16_TO_STREAM(p, mps);
  UINT16_TO_STREAM(p, initial_credit);

  for (uint16_t cid : p_lcb->pending_ecoc_connection_cids) {
  for (int i = 0; i < p_lcb->pending_ecoc_conn_cnt; i++) {
    uint16_t cid = p_lcb->pending_ecoc_connection_cids[i];
    L2CAP_TRACE_DEBUG("\n\t cid: ", cid);
    UINT16_TO_STREAM(p, cid);
  }
@@ -2856,9 +2857,8 @@ void l2cu_send_peer_credit_based_conn_res(tL2C_CCB* p_ccb,
  uint8_t* p;

  L2CAP_TRACE_DEBUG("%s", __func__);
  uint8_t rsp_len =
      L2CAP_CMD_CREDIT_BASED_CONN_RES_MIN_LEN +
      p_ccb->p_lcb->pending_ecoc_connection_cids.size() * sizeof(uint16_t);
  uint8_t rsp_len = L2CAP_CMD_CREDIT_BASED_CONN_RES_MIN_LEN +
                    p_ccb->p_lcb->pending_ecoc_conn_cnt * sizeof(uint16_t);

  p_buf = l2cu_build_header(p_ccb->p_lcb, rsp_len,
                            L2CAP_CMD_CREDIT_BASED_CONN_RES, p_ccb->remote_id);
@@ -2891,7 +2891,8 @@ void l2cu_send_peer_credit_based_conn_res(tL2C_CCB* p_ccb,
   * the stack.
   * If there is valid cid, we need to verify if it is accepted by upper layer.
   */
  for (uint16_t cid : p_ccb->p_lcb->pending_ecoc_connection_cids) {
  for (int i = 0; i < p_ccb->p_lcb->pending_ecoc_conn_cnt; i++) {
    uint16_t cid = p_ccb->p_lcb->pending_ecoc_connection_cids[i];
    if (cid == 0) {
      UINT16_TO_STREAM(p, 0);
      continue;