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

Commit 5c298722 authored by Jayden Kim's avatar Jayden Kim
Browse files

Set the initial local credits to 0 for offload LE socket

Bug: 342012881
Bug: 367419086
Test: m -j
Change-Id: Ie2967885b07a2da27ee16027b894db65cfbf2f58
parent 88ba5e07
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -851,6 +851,13 @@ static void btsock_l2cap_server_listen(l2cap_socket* sock) {
  /* Setup ETM settings: mtu will be set below */
  std::unique_ptr<tL2CAP_CFG_INFO> cfg = std::make_unique<tL2CAP_CFG_INFO>(
          tL2CAP_CFG_INFO{.fcr_present = true, .fcr = kDefaultErtmOptions});
  /* For hardware offload data path, host stack sets the initial credits to 0. The offload stack
   * should send initial credits to peer device through L2CAP signaling command when the data path
   * is switched successfully. */
  if (sock->data_path == BTSOCK_DATA_PATH_HARDWARE_OFFLOAD) {
    cfg->init_credit_present = true;
    cfg->init_credit = 0;
  }

  std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info;
  if (!sock->is_le_coc) {
@@ -925,6 +932,13 @@ static bt_status_t btsock_l2cap_listen_or_connect(const char* name, const RawAdd
    /* Setup ETM settings: mtu will be set below */
    std::unique_ptr<tL2CAP_CFG_INFO> cfg = std::make_unique<tL2CAP_CFG_INFO>(
            tL2CAP_CFG_INFO{.fcr_present = true, .fcr = kDefaultErtmOptions});
    /* For hardware offload data path, host stack sets the initial credits to 0. The offload stack
     * should send initial credits to peer device through L2CAP signaling command when the data path
     * is switched successfully. */
    if (sock->data_path == BTSOCK_DATA_PATH_HARDWARE_OFFLOAD) {
      cfg->init_credit_present = true;
      cfg->init_credit = 0;
    }

    std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info;
    if (!sock->is_le_coc) {
+2 −1
Original line number Diff line number Diff line
@@ -213,7 +213,8 @@ uint16_t GAP_ConnOpen(const char* /* p_serv_name */, uint8_t service_id, bool is

  /* Configure L2CAP COC, if transport is LE */
  if (transport == BT_TRANSPORT_LE) {
    p_ccb->local_coc_cfg.credits = L2CA_LeCreditDefault();
    p_ccb->local_coc_cfg.credits =
            (p_ccb->cfg.init_credit_present) ? p_ccb->cfg.init_credit : L2CA_LeCreditDefault();
    p_ccb->local_coc_cfg.mtu = p_cfg->mtu;

    uint16_t max_mps = bluetooth::shim::GetController()->GetLeBufferSize().le_data_packet_length_;
+2 −0
Original line number Diff line number Diff line
@@ -129,6 +129,8 @@ typedef struct {
  uint8_t fcs;      /* '0' if desire is to bypass FCS, otherwise '1' */
  bool ext_flow_spec_present;
  tHCI_EXT_FLOW_SPEC ext_flow_spec;
  bool init_credit_present;
  uint16_t init_credit;
  uint16_t flags; /* bit 0: 0-no continuation, 1-continuation */
} tL2CAP_CFG_INFO;

+3 −2
Original line number Diff line number Diff line
@@ -780,8 +780,9 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) {
      p_ccb->local_conn_cfg.mtu = L2CAP_SDU_LENGTH_LE_MAX;
      p_ccb->local_conn_cfg.mps =
              bluetooth::shim::GetController()->GetLeBufferSize().le_data_packet_length_;
      p_ccb->local_conn_cfg.credits = L2CA_LeCreditDefault();
      p_ccb->remote_credit_count = L2CA_LeCreditDefault();
      p_ccb->local_conn_cfg.credits = p_rcb->coc_cfg.credits;

      p_ccb->remote_credit_count = p_rcb->coc_cfg.credits;

      p_ccb->peer_conn_cfg.mtu = mtu;
      p_ccb->peer_conn_cfg.mps = mps;
+3 −0
Original line number Diff line number Diff line
@@ -3331,6 +3331,9 @@ void l2cu_send_peer_ble_credit_based_conn_res(tL2C_CCB* p_ccb, tL2CAP_LE_RESULT_
  p = (uint8_t*)(p_buf + 1) + L2CAP_SEND_CMD_OFFSET + HCI_DATA_PREAMBLE_SIZE + L2CAP_PKT_OVERHEAD +
      L2CAP_CMD_OVERHEAD;

  log::verbose("local cid: {}, mtu: {}, mps: {}, initial credits: {}", p_ccb->local_cid,
               p_ccb->local_conn_cfg.mtu, p_ccb->local_conn_cfg.mps, p_ccb->local_conn_cfg.credits);

  UINT16_TO_STREAM(p, p_ccb->local_cid);              /* Local CID */
  UINT16_TO_STREAM(p, p_ccb->local_conn_cfg.mtu);     /* MTU */
  UINT16_TO_STREAM(p, p_ccb->local_conn_cfg.mps);     /* MPS */