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

Commit 323f73de authored by Rahul Arya's avatar Rahul Arya
Browse files

Avoid out-of-order L2CAP CoC callbacks on channel creation

When L2CA_ConnectLECocReq is called and starts the channels state
machine, we do so synchronously. If the state machine experiences a
failure and invokes a callback, it does so again synchronously, so the
failure callback arrives *before* the connection request completes.

By deferring the state transition until after the connect request
returns, we fix the order of events.

Bug: 258223088
Test: manual
Merged-In: I698c0e5e514485b9af8e21f136b5aa7c918a6d4c
Change-Id: I698c0e5e514485b9af8e21f136b5aa7c918a6d4c
(cherry picked from commit 784d750b)
parent f0a865db
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -205,6 +205,7 @@ fn parse_hci_adapter(flags: &mut InitFlags, values: Vec<&str>) {
init_flags!(
    // LINT.IfChange
    flags: {
        asynchronously_start_l2cap_coc = true,
        btaa_hci = true,
        btm_dm_flush_discovery_queue_on_search_cancel,
        gatt_robust_caching_client = true,
+1 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ mod ffi {
        fn load(flags: Vec<String>);
        fn set_all_for_testing();

        fn asynchronously_start_l2cap_coc_is_enabled() -> bool;
        fn btaa_hci_is_enabled() -> bool;
        fn btm_dm_flush_discovery_queue_on_search_cancel_is_enabled() -> bool;
        fn gatt_robust_caching_client_is_enabled() -> bool;
+14 −3
Original line number Diff line number Diff line
@@ -33,11 +33,13 @@
#include <string>

#include "device/include/controller.h"  // TODO Remove
#include "gd/common/init_flags.h"
#include "main/shim/shim.h"
#include "osi/include/allocator.h"
#include "osi/include/log.h"
#include "stack/btm/btm_sec.h"
#include "stack/include/bt_hdr.h"
#include "stack/include/btu.h"  // do_in_main_thread
#include "stack/include/l2c_api.h"
#include "stack/l2cap/l2c_int.h"
#include "types/raw_address.h"
@@ -563,9 +565,18 @@ uint16_t L2CA_ConnectLECocReq(uint16_t psm, const RawAddress& p_bd_addr,
  if (p_lcb->link_state == LST_CONNECTED) {
    if (p_ccb->p_lcb->transport == BT_TRANSPORT_LE) {
      L2CAP_TRACE_DEBUG("%s LE Link is up", __func__);
      // post this asynchronously to avoid out-of-order callback invocation
      // should this operation fail
      if (bluetooth::common::init_flags::
              asynchronously_start_l2cap_coc_is_enabled()) {
        do_in_main_thread(FROM_HERE,
                          base::Bind(&l2c_csm_execute, base::Unretained(p_ccb),
                                     L2CEVT_L2CA_CONNECT_REQ, nullptr));
      } else {
        l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_REQ, NULL);
      }
    }
  }

  /* If link is disconnecting, save link info to retry after disconnect
   * Possible Race condition when a reconnect occurs
@@ -843,8 +854,8 @@ std::vector<uint16_t> L2CA_ConnectCreditBasedReq(uint16_t psm,
 *
 *  Description      Start reconfigure procedure on Connection Oriented Channel.
 *
 *  Parameters:      Vector of channels for which configuration should be changed
 *                   New local channel configuration
 *  Parameters:      Vector of channels for which configuration should be
 *changed New local channel configuration
 *
 *  Return value:    true if peer is connected
 *