OSDN Git Service

Fix LE disconnecting right after pairing
authorJakub Pawlowski <jpawlowski@google.com>
Thu, 27 Apr 2017 11:52:34 +0000 (04:52 -0700)
committerJakub Pawlowski <jpawlowski@google.com>
Thu, 27 Apr 2017 19:53:51 +0000 (12:53 -0700)
When a device connect to android over LE, the default policy is to keep
this connection. If any app "claims" this connnection, and then stop
using it, we'll disconnect from the device after a short timeout.

If pairing is triggered to such device, that is connected but not used
by any app, it will cause disconnect after the pairing is finished. This
is because using SMP over fixed LE L2CAP channel is conseidered as
connecting, using, and disconnecting a channel by the stack. This is
obvious logic error - using fixed channels should not require
"connecting" to them.

As a temporary workaround, do not trigger a timeout when a fixed SMP
channel is closed over LE.

For LE only devices, this means they will stay connected after the
pairing until some app starts using them or they disconnect. For dual
mode devices, Classic connection will be established and SDP will be
performed. The classic connection will be disconnected if no app will
use it, and the LE connection to the device will stay up.

Bug: 37352720
Test: manual
Change-Id: Ic9d688aacf84e0267277b12b28dfa7cc57fdcea6
(cherry picked from commit 7c8bab231328956d3b7569280cb162be4e345422)

stack/l2cap/l2c_utils.cc

index 75bef4c..f6728d6 100644 (file)
@@ -1622,6 +1622,12 @@ void l2cu_release_ccb(tL2C_CCB* p_ccb) {
   /* If no channels on the connection, start idle timeout */
   if ((p_lcb) && p_lcb->in_use && (p_lcb->link_state == LST_CONNECTED)) {
     if (!p_lcb->ccb_queue.p_first_ccb) {
+      // Closing a security channel on LE device should not start connection
+      // timeout
+      if (p_lcb->transport == BT_TRANSPORT_LE &&
+          p_ccb->local_cid == L2CAP_SMP_CID)
+        return;
+
       l2cu_no_dynamic_ccbs(p_lcb);
     } else {
       /* Link is still active, adjust channel quotas. */