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

Commit 3f638e5f authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Make L2CAP credit config modifiable"

parents c1353c4a 4f221c97
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -153,7 +153,8 @@ struct eatt_impl {
    tL2CAP_LE_CFG_INFO local_coc_cfg = {
        .mtu = eatt_dev->rx_mtu_,
        .mps = eatt_dev->rx_mps_ < max_mps ? eatt_dev->rx_mps_ : max_mps,
        .credits = L2CAP_LE_CREDIT_DEFAULT};
        .credits = L2CA_LeCreditDefault(),
    };

    if (!L2CA_ConnectCreditBasedRsp(bda, identifier, lcids, L2CAP_CONN_OK,
                                    &local_coc_cfg))
@@ -586,7 +587,7 @@ struct eatt_impl {
    tL2CAP_LE_CFG_INFO local_coc_cfg = {
        .mtu = eatt_dev->rx_mtu_,
        .mps = eatt_dev->rx_mps_,
        .credits = L2CAP_LE_CREDIT_DEFAULT,
        .credits = L2CA_LeCreditDefault(),
        .number_of_channels = num_of_channels,
    };

+1 −1
Original line number Diff line number Diff line
@@ -207,7 +207,7 @@ uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id,

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

    uint16_t max_mps = controller_get_interface()->get_acl_data_size_ble();
+3 −6
Original line number Diff line number Diff line
@@ -180,14 +180,11 @@ constexpr uint16_t L2CAP_LE_CREDIT_MAX = 65535;

// This is initial amout of credits we send, and amount to which we increase
// credits once they fall below threshold
constexpr uint16_t L2CAP_LE_CREDIT_DEFAULT = 0xffff;
uint16_t L2CA_LeCreditDefault();

// If credit count on remote fall below this value, we send back credits to
// reach default value.
constexpr uint16_t L2CAP_LE_CREDIT_THRESHOLD = 0x0040;

static_assert(L2CAP_LE_CREDIT_THRESHOLD < L2CAP_LE_CREDIT_DEFAULT,
              "Threshold must be smaller than default credits");
uint16_t L2CA_LeCreditThreshold();

// Max number of CIDs in the L2CAP CREDIT BASED CONNECTION REQUEST
constexpr uint16_t L2CAP_CREDIT_BASED_MAX_CIDS = 5;
@@ -199,7 +196,7 @@ struct tL2CAP_LE_CFG_INFO {
  uint16_t result; /* Only used in confirm messages */
  uint16_t mtu = 100;
  uint16_t mps = 100;
  uint16_t credits = L2CAP_LE_CREDIT_DEFAULT;
  uint16_t credits = L2CA_LeCreditDefault();
  uint8_t number_of_channels = L2CAP_CREDIT_BASED_MAX_CIDS;
};

+24 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@
#include "main/shim/shim.h"
#include "osi/include/allocator.h"
#include "osi/include/log.h"
#include "osi/include/properties.h"
#include "stack/btm/btm_sec.h"
#include "stack/include/bt_hdr.h"
#include "stack/include/btu.h"  // do_in_main_thread
@@ -70,6 +71,29 @@ uint16_t L2CA_Register2(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
  return ret;
}

uint16_t L2CA_LeCreditDefault() {
  static const uint16_t sL2CAP_LE_CREDIT_DEFAULT =
      (uint16_t)osi_property_get_int32(
          "bluetooth.l2cap.le.credit_default.value", 0xffff);
  return sL2CAP_LE_CREDIT_DEFAULT;
}

uint16_t L2CA_LeCreditThreshold() {
  static const uint16_t sL2CAP_LE_CREDIT_THRESHOLD =
      (uint16_t)osi_property_get_int32(
          "bluetooth.l2cap.le.credit_threshold.value", 0x0040);
  return sL2CAP_LE_CREDIT_THRESHOLD;
}

static bool check_l2cap_credit() {
  CHECK(L2CA_LeCreditThreshold() < L2CA_LeCreditDefault())
      << "Threshold must be smaller than default credits";
  return true;
}

// Replace static assert with startup assert depending of the config
static const bool enforce_assert = check_l2cap_credit();

/*******************************************************************************
 *
 * Function         L2CA_Register
+1 −1
Original line number Diff line number Diff line
@@ -1008,7 +1008,7 @@ 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 =
          controller_get_interface()->get_acl_data_size_ble();
      p_ccb->local_conn_cfg.credits = L2CAP_LE_CREDIT_DEFAULT,
      p_ccb->local_conn_cfg.credits = L2CA_LeCreditDefault(),

      p_ccb->peer_conn_cfg.mtu = mtu;
      p_ccb->peer_conn_cfg.mps = mps;
Loading