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

Commit c24851b3 authored by Rahul Arya's avatar Rahul Arya
Browse files

Fix infinite L2CAP timeout when ATT is used without GATT clients

If we do ATT operations without a GATT client, the channel timeout stays
at the default value (infinite) which prevents the ACL link from
disconnecting.

The timeout is set to zero when the *last* GATT client disconnects, but
of course this doesn't work if there never are *any* GATT clients, yet
ATT operations (such as service discovery) are taking place.

Test: atest pts-bot?
Bug: 251954527
Change-Id: I2990fd8892ab0f442fd7847b34812e29d832baac
parent 5457ff2c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -172,6 +172,7 @@ fn parse_hci_adapter(flags: &mut InitFlags, values: Vec<&str>) {
init_flags!(
    flags: {
        btaa_hci = true,
        finite_att_timeout = true,
        gatt_robust_caching_client = true,
        gatt_robust_caching_server,
        gd_core,
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ mod ffi {
        fn set_all_for_testing();

        fn btaa_hci_is_enabled() -> bool;
        fn finite_att_timeout_is_enabled() -> bool;
        fn gatt_robust_caching_client_is_enabled() -> bool;
        fn gatt_robust_caching_server_is_enabled() -> bool;
        fn gd_core_is_enabled() -> bool;
+7 −3
Original line number Diff line number Diff line
@@ -22,11 +22,14 @@
 *
 ******************************************************************************/

#include <base/logging.h>

#include "bt_target.h"
#include "bt_utils.h"
#include "btif/include/btif_storage.h"
#include "connection_manager.h"
#include "device/include/interop.h"
#include "gd/common/init_flags.h"
#include "internal_include/stack_config.h"
#include "l2c_api.h"
#include "osi/include/allocator.h"
@@ -40,8 +43,6 @@
#include "stack/include/l2cap_acl_interface.h"
#include "types/raw_address.h"

#include <base/logging.h>

using base::StringPrintf;
using bluetooth::eatt::EattExtension;

@@ -113,7 +114,10 @@ void gatt_init(void) {
  fixed_reg.pL2CA_FixedConn_Cb = gatt_le_connect_cback;
  fixed_reg.pL2CA_FixedData_Cb = gatt_le_data_ind;
  fixed_reg.pL2CA_FixedCong_Cb = gatt_le_cong_cback; /* congestion callback */
  fixed_reg.default_idle_tout = 0xffff; /* 0xffff default idle timeout */
  fixed_reg.default_idle_tout =
      bluetooth::common::init_flags::finite_att_timeout_is_enabled()
          ? 2 /* We allow 2s for GATT clients to connect once the link is up */
          : L2CAP_NO_IDLE_TIMEOUT;

  L2CA_RegisterFixedChannel(L2CAP_ATT_CID, &fixed_reg);

+2 −0
Original line number Diff line number Diff line
@@ -101,6 +101,8 @@ typedef uint8_t tL2CAP_CHNL_DATA_RATE;
#define L2C_IS_VALID_PSM(psm) (((psm)&0x0101) == 0x0001)
#define L2C_IS_VALID_LE_PSM(psm) (((psm) > 0x0000) && ((psm) < 0x0100))

#define L2CAP_NO_IDLE_TIMEOUT 0xFFFF

/*****************************************************************************
 *  Type Definitions
 ****************************************************************************/
+0 −1
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@

constexpr uint16_t L2CAP_CREDIT_BASED_MIN_MTU = 64;
constexpr uint16_t L2CAP_CREDIT_BASED_MIN_MPS = 64;
#define L2CAP_NO_IDLE_TIMEOUT 0xFFFF

/*
 * Timeout values (in milliseconds).