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

Commit b6e2ac00 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

bta_gattc: Fix number of max gatt connection client control blocks

Each GATT client application in worst case might have instance per
connection.
Without this change and having LeAudio support which per set of CSIP
based devices might take up to 12 GATT clients (vc, leaudio, csip,
battery service, bass, hap) * 2, the pool will end very quickly

Bug: 325438660
Test: mmm packages/modules/Bluetooth
Flag: Exempt, just increase number of control blocks for avoid future
issues
Test: manual testing multiple devices connection

Change-Id: Ia359091ae9026ac5a8e5980d883e0fbe20001e18
parent 93365c94
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -248,7 +248,7 @@ void bta_gattc_deregister(tBTA_GATTC_RCB* p_clreg) {
  }

  /* close all CLCB related to this app */
  for (uint8_t i = 0; i < BTA_GATTC_CLCB_MAX; i++) {
  for (size_t i = 0; i < BTA_GATTC_CLCB_MAX; i++) {
    if (!bta_gattc_cb.clcb[i].in_use || (bta_gattc_cb.clcb[i].p_rcb != p_clreg))
      continue;

@@ -698,7 +698,7 @@ void bta_gattc_close(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data) {

/** when a SRCB finished discovery, tell all related clcb */
void bta_gattc_reset_discover_st(tBTA_GATTC_SERV* p_srcb, tGATT_STATUS status) {
  for (uint8_t i = 0; i < BTA_GATTC_CLCB_MAX; i++) {
  for (size_t i = 0; i < BTA_GATTC_CLCB_MAX; i++) {
    if (bta_gattc_cb.clcb[i].p_srcb == p_srcb) {
      bta_gattc_cb.clcb[i].status = status;
      bta_gattc_sm_execute(&bta_gattc_cb.clcb[i], BTA_GATTC_DISCOVER_CMPL_EVT,
@@ -729,9 +729,7 @@ void bta_gattc_disc_close(tBTA_GATTC_CLCB* p_clcb,

/** when a SRCB start discovery, tell all related clcb and set the state */
static void bta_gattc_set_discover_st(tBTA_GATTC_SERV* p_srcb) {
  uint8_t i;

  for (i = 0; i < BTA_GATTC_CLCB_MAX; i++) {
  for (size_t i = 0; i < BTA_GATTC_CLCB_MAX; i++) {
    if (bta_gattc_cb.clcb[i].p_srcb == p_srcb) {
      bta_gattc_cb.clcb[i].status = GATT_SUCCESS;
      bta_gattc_cb.clcb[i].state = BTA_GATTC_DISCOVER_ST;
@@ -1450,7 +1448,7 @@ void bta_gattc_process_api_refresh(const RawAddress& remote_bda) {
    if (p_srvc_cb->connected && p_srvc_cb->num_clcb != 0) {
      bool found = false;
      tBTA_GATTC_CLCB* p_clcb = &bta_gattc_cb.clcb[0];
      for (uint8_t i = 0; i < BTA_GATTC_CLCB_MAX; i++, p_clcb++) {
      for (size_t i = 0; i < BTA_GATTC_CLCB_MAX; i++, p_clcb++) {
        if (p_clcb->in_use && p_clcb->p_srcb == p_srvc_cb) {
          found = true;
          break;
+6 −2
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ typedef uint16_t tBTA_GATTC_INT_EVT;

#define BTA_GATTC_SERVICE_CHANGED_LEN 4

/* max client application GATTC can support */
/* Max client application GATTC can support */
#ifndef BTA_GATTC_CL_MAX
#define BTA_GATTC_CL_MAX 32
#endif
@@ -80,8 +80,12 @@ typedef uint16_t tBTA_GATTC_INT_EVT;
#define BTA_GATTC_KNOWN_SR_MAX 255
#endif

/* This represents number of gatt client control blocks per connection.
 *  Because of that this value shall depends on the number of possible GATT
 *  connections  GATT_MAX_PHY_CHANNEL
 */
#ifndef BTA_GATTC_CLCB_MAX
#define BTA_GATTC_CLCB_MAX GATT_CL_MAX_LCB
#define BTA_GATTC_CLCB_MAX ((GATT_MAX_PHY_CHANNEL) * (BTA_GATTC_CL_MAX))
#endif

#define BTA_GATTC_WRITE_PREPARE GATT_WRITE_PREPARE
+4 −7
Original line number Diff line number Diff line
@@ -98,9 +98,8 @@ tBTA_GATTC_CLCB* bta_gattc_find_clcb_by_cif(uint8_t client_if,
                                            const RawAddress& remote_bda,
                                            tBT_TRANSPORT transport) {
  tBTA_GATTC_CLCB* p_clcb = &bta_gattc_cb.clcb[0];
  uint8_t i;

  for (i = 0; i < BTA_GATTC_CLCB_MAX; i++, p_clcb++) {
  for (size_t i = 0; i < BTA_GATTC_CLCB_MAX; i++, p_clcb++) {
    if (p_clcb->in_use && p_clcb->p_rcb->client_if == client_if &&
        p_clcb->transport == transport && p_clcb->bda == remote_bda)
      return p_clcb;
@@ -118,9 +117,8 @@ tBTA_GATTC_CLCB* bta_gattc_find_clcb_by_cif(uint8_t client_if,
 ******************************************************************************/
tBTA_GATTC_CLCB* bta_gattc_find_clcb_by_conn_id(uint16_t conn_id) {
  tBTA_GATTC_CLCB* p_clcb = &bta_gattc_cb.clcb[0];
  uint8_t i;

  for (i = 0; i < BTA_GATTC_CLCB_MAX; i++, p_clcb++) {
  for (size_t i = 0; i < BTA_GATTC_CLCB_MAX; i++, p_clcb++) {
    if (p_clcb->in_use && p_clcb->bta_conn_id == conn_id) return p_clcb;
  }
  return NULL;
@@ -138,10 +136,9 @@ tBTA_GATTC_CLCB* bta_gattc_find_clcb_by_conn_id(uint16_t conn_id) {
tBTA_GATTC_CLCB* bta_gattc_clcb_alloc(tGATT_IF client_if,
                                      const RawAddress& remote_bda,
                                      tBT_TRANSPORT transport) {
  uint8_t i_clcb = 0;
  tBTA_GATTC_CLCB* p_clcb = NULL;

  for (i_clcb = 0; i_clcb < BTA_GATTC_CLCB_MAX; i_clcb++) {
  for (int i_clcb = 0; i_clcb < BTA_GATTC_CLCB_MAX; i_clcb++) {
    if (!bta_gattc_cb.clcb[i_clcb].in_use) {
#if (BTA_GATT_DEBUG == TRUE)
      log::verbose("found clcb:{} available", i_clcb);
@@ -864,7 +861,7 @@ void bta_gatt_client_dump(int fd) {
  stream << "  -- used: " << entry_count << "\n";
  entry_count = 0;
  stream << " ->clcb (BTA_GATTC_CLCB_MAX=" << BTA_GATTC_CLCB_MAX << ")\n";
  for (int i = 0; i < BTA_GATTC_CLCB_MAX; i++) {
  for (size_t i = 0; i < BTA_GATTC_CLCB_MAX; i++) {
    tBTA_GATTC_CLCB* p_clcb = &bta_gattc_cb.clcb[i];
    if (!p_clcb->in_use) {
      continue;