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

Commit 4d418bdf authored by Omair Kamil's avatar Omair Kamil Committed by Automerger Merge Worker
Browse files

Merge "Use a system property to drive the maximum number of GATT connections."...

Merge "Use a system property to drive the maximum number of GATT connections." into main am: b8cefe4d

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/3003631



Change-Id: I1125a358a3de126b141f32ebdb4e283bdd290ab7
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents e5cdf479 b8cefe4d
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -390,8 +390,15 @@
 * create l2cap connection, it will use this fixed ID. */
#define CONN_MGR_ID_L2CAP (GATT_MAX_APPS + 10)

/* This value is used for static allocation of resources. The actual maximum at
 * runtime is controlled by a system property. */
#ifndef GATT_MAX_PHY_CHANNEL
#define GATT_MAX_PHY_CHANNEL 7
#define GATT_MAX_PHY_CHANNEL 16
#endif

/* Devices must support at least 8 GATT channels per the CDD. */
#ifndef GATT_MAX_PHY_CHANNEL_FLOOR
#define GATT_MAX_PHY_CHANNEL_FLOOR 8
#endif

/* Used for conformance testing ONLY */
+37 −24
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include "internal_include/bt_target.h"
#include "os/log.h"
#include "osi/include/allocator.h"
#include "osi/include/properties.h"
#include "rust/src/connection/ffi/connection_shim.h"
#include "stack/btm/btm_sec.h"
#include "stack/eatt/eatt.h"
@@ -55,8 +56,8 @@ using namespace bluetooth::legacy::stack::sdp;
using namespace bluetooth;

using bluetooth::Uuid;
using bluetooth::eatt::EattExtension;
using bluetooth::eatt::EattChannel;
using bluetooth::eatt::EattExtension;

/* check if [x, y] and [a, b] have overlapping range */
#define GATT_VALIDATE_HANDLE_RANGE(x, y, a, b) ((y) >= (a) && (x) <= (b))
@@ -99,13 +100,22 @@ const char* const op_code_name[] = {"UNKNOWN",
uint16_t gatt_get_local_mtu(void) {
  /* Default ATT MTU must not be greater than GATT_MAX_MTU_SIZE, nor smaller
   * than GATT_DEF_BLE_MTU_SIZE */
  const static uint16_t ATT_MTU_DEFAULT =
  static const uint16_t ATT_MTU_DEFAULT =
      std::max(std::min(bluetooth::common::init_flags::get_att_mtu_default(),
                        GATT_MAX_MTU_SIZE),
               GATT_DEF_BLE_MTU_SIZE);
  return ATT_MTU_DEFAULT;
}

uint16_t gatt_get_max_phy_channel() {
  static const uint16_t MAX_PHY_CHANNEL = std::min(
      std::max(osi_property_get_int32(
                   "bluetooth.core.le.max_number_of_concurrent_connections", 0),
               GATT_MAX_PHY_CHANNEL_FLOOR),
      GATT_MAX_PHY_CHANNEL);
  return MAX_PHY_CHANNEL;
}

/*******************************************************************************
 *
 * Function         gatt_free_pending_ind
@@ -280,7 +290,7 @@ bool gatt_find_the_connected_bda(uint8_t start_idx, RawAddress& bda,
  bool found = false;
  log::debug("start_idx={}", start_idx);

  for (i = start_idx; i < GATT_MAX_PHY_CHANNEL; i++) {
  for (i = start_idx; i < gatt_get_max_phy_channel(); i++) {
    if (gatt_cb.tcb[i].in_use && gatt_cb.tcb[i].ch_state == GATT_CH_OPEN) {
      bda = gatt_cb.tcb[i].peer_bda;
      *p_found_idx = i;
@@ -368,7 +378,7 @@ bool gatt_is_bda_connected(const RawAddress& bda) {
  uint8_t i = 0;
  bool connected = false;

  for (i = 0; i < GATT_MAX_PHY_CHANNEL; i++) {
  for (i = 0; i < gatt_get_max_phy_channel(); i++) {
    if (gatt_cb.tcb[i].in_use && gatt_cb.tcb[i].peer_bda == bda) {
      connected = true;
      break;
@@ -390,7 +400,7 @@ uint8_t gatt_find_i_tcb_by_addr(const RawAddress& bda,
                                tBT_TRANSPORT transport) {
  uint8_t i = 0;

  for (; i < GATT_MAX_PHY_CHANNEL; i++) {
  for (; i < gatt_get_max_phy_channel(); i++) {
    if (gatt_cb.tcb[i].peer_bda == bda &&
        gatt_cb.tcb[i].transport == transport) {
      return i;
@@ -411,7 +421,7 @@ uint8_t gatt_find_i_tcb_by_addr(const RawAddress& bda,
tGATT_TCB* gatt_get_tcb_by_idx(uint8_t tcb_idx) {
  tGATT_TCB* p_tcb = NULL;

  if ((tcb_idx < GATT_MAX_PHY_CHANNEL) && gatt_cb.tcb[tcb_idx].in_use)
  if ((tcb_idx < gatt_get_max_phy_channel()) && gatt_cb.tcb[tcb_idx].in_use)
    p_tcb = &gatt_cb.tcb[tcb_idx];

  return p_tcb;
@@ -450,7 +460,7 @@ void gatt_tcb_dump(int fd) {
  std::stringstream stream;
  int in_use_cnt = 0;

  for (int i = 0; i < GATT_MAX_PHY_CHANNEL; i++) {
  for (int i = 0; i < gatt_get_max_phy_channel(); i++) {
    tGATT_TCB* p_tcb = &gatt_cb.tcb[i];

    if (p_tcb->in_use) {
@@ -464,7 +474,7 @@ void gatt_tcb_dump(int fd) {
  }

  dprintf(fd, "TCB (GATT_MAX_PHY_CHANNEL: %d) in_use: %d\n%s\n",
          GATT_MAX_PHY_CHANNEL, in_use_cnt, stream.str().c_str());
          gatt_get_max_phy_channel(), in_use_cnt, stream.str().c_str());
}

/*******************************************************************************
@@ -483,7 +493,7 @@ tGATT_TCB* gatt_allocate_tcb_by_bdaddr(const RawAddress& bda,
  if (j != GATT_INDEX_INVALID) return &gatt_cb.tcb[j];

  /* find free tcb */
  for (int i = 0; i < GATT_MAX_PHY_CHANNEL; i++) {
  for (int i = 0; i < gatt_get_max_phy_channel(); i++) {
    tGATT_TCB* p_tcb = &gatt_cb.tcb[i];
    if (p_tcb->in_use) continue;

@@ -648,7 +658,8 @@ void gatt_stop_rsp_timer(tGATT_CLCB* p_clcb) {
void gatt_start_conf_timer(tGATT_TCB* p_tcb, uint16_t cid) {
  /* start notification cache timer */
  if (p_tcb->eatt && cid != L2CAP_ATT_CID)
    EattExtension::GetInstance()->StartIndicationConfirmationTimer(p_tcb->peer_bda, cid);
    EattExtension::GetInstance()->StartIndicationConfirmationTimer(
        p_tcb->peer_bda, cid);
  else
    alarm_set_on_mloop(p_tcb->conf_timer, GATT_WAIT_FOR_RSP_TIMEOUT_MS,
                       gatt_indication_confirmation_timeout, p_tcb);
@@ -666,7 +677,8 @@ void gatt_start_conf_timer(tGATT_TCB* p_tcb, uint16_t cid) {
void gatt_stop_conf_timer(tGATT_TCB& tcb, uint16_t cid) {
  /* start notification cache timer */
  if (tcb.eatt && cid != L2CAP_ATT_CID)
    EattExtension::GetInstance()->StopIndicationConfirmationTimer(tcb.peer_bda, cid);
    EattExtension::GetInstance()->StopIndicationConfirmationTimer(tcb.peer_bda,
                                                                  cid);
  else
    alarm_cancel(tcb.conf_timer);
}
@@ -904,8 +916,7 @@ tGATT_STATUS gatt_send_error_rsp(tGATT_TCB& tcb, uint16_t cid, uint8_t err_code,
  } else
    status = GATT_INSUF_RESOURCE;

  if (deq)
      gatt_dequeue_sr_cmd(tcb, cid);
  if (deq) gatt_dequeue_sr_cmd(tcb, cid);

  return status;
}
@@ -1093,7 +1104,8 @@ bool gatt_tcb_get_cid_available_for_indication(tGATT_TCB* p_tcb,
                                               uint16_t* cid_p) {
  if (p_tcb->eatt && eatt_support) {
    EattChannel* channel =
        EattExtension::GetInstance()->GetChannelAvailableForIndication(p_tcb->peer_bda);
        EattExtension::GetInstance()->GetChannelAvailableForIndication(
            p_tcb->peer_bda);
    if (channel) {
      *indicated_handle_p = &channel->indicate_handle_;
      *cid_p = channel->cid_;
@@ -1153,7 +1165,8 @@ bool gatt_tcb_find_indicate_handle(tGATT_TCB& tcb, uint16_t cid,
uint16_t gatt_tcb_get_att_cid(tGATT_TCB& tcb, bool eatt_support) {
  if (eatt_support && tcb.eatt) {
    EattChannel* channel =
        EattExtension::GetInstance()->GetChannelAvailableForClientRequest(tcb.peer_bda);
        EattExtension::GetInstance()->GetChannelAvailableForClientRequest(
            tcb.peer_bda);
    if (channel) {
      return channel->cid_;
    }
@@ -1286,11 +1299,11 @@ tGATT_TCB* gatt_find_tcb_by_cid(uint16_t lcid) {
  uint16_t xx = 0;
  tGATT_TCB* p_tcb = NULL;

  for (xx = 0; xx < GATT_MAX_PHY_CHANNEL; xx++) {
  for (xx = 0; xx < gatt_get_max_phy_channel(); xx++) {
    if (gatt_cb.tcb[xx].in_use &&
        ((gatt_cb.tcb[xx].att_lcid == lcid) ||
         ((EattExtension::GetInstance()->FindEattChannelByCid(gatt_cb.tcb[xx].peer_bda,
                                                      lcid) != nullptr)))) {
         ((EattExtension::GetInstance()->FindEattChannelByCid(
               gatt_cb.tcb[xx].peer_bda, lcid) != nullptr)))) {
      p_tcb = &gatt_cb.tcb[xx];
      break;
    }
@@ -1330,8 +1343,8 @@ tGATT_SR_CMD* gatt_sr_get_cmd_by_trans_id(tGATT_TCB* p_tcb, uint32_t trans_id) {

  if (!p_tcb->eatt) return nullptr;

  EattChannel* channel =
      EattExtension::GetInstance()->FindEattChannelByTransId(p_tcb->peer_bda, trans_id);
  EattChannel* channel = EattExtension::GetInstance()->FindEattChannelByTransId(
      p_tcb->peer_bda, trans_id);
  if (!channel) return nullptr;

  return &channel->server_outstanding_cmd_;
@@ -1584,8 +1597,8 @@ bool gatt_cmd_enq(tGATT_TCB& tcb, tGATT_CLCB* p_clcb, bool to_send,
  if (p_clcb->cid == tcb.att_lcid) {
    tcb.cl_cmd_q.push_back(cmd);
  } else {
    EattChannel* channel =
        EattExtension::GetInstance()->FindEattChannelByCid(tcb.peer_bda, cmd.cid);
    EattChannel* channel = EattExtension::GetInstance()->FindEattChannelByCid(
        tcb.peer_bda, cmd.cid);
    if (channel == nullptr) {
      log::warn("{}, cid 0x{:02x} already disconnected",
                ADDRESS_TO_LOGGABLE_CSTR(tcb.peer_bda), cmd.cid);