OSDN Git Service

Allocate lcb when connection complete if can't find one
authorChienyuan <chienyuanhuang@google.com>
Wed, 29 Aug 2018 05:38:19 +0000 (13:38 +0800)
committerChienyuan <chienyuanhuang@google.com>
Thu, 6 Sep 2018 08:11:36 +0000 (16:11 +0800)
When BT stack sends create connection command and receive connection
request at the same time, connection request will reuse the link control
block created by create connection command. But the link control block
will be released before connection complete due to controller busy.

Bug:112818458
Test: manual - turn on BT and turn on Headset within little time gap
Change-Id: Ie30c655b933250f1709ba10c578ea5f30ea13139

stack/l2cap/l2c_link.cc

index b9b905d..3c10f18 100644 (file)
@@ -159,10 +159,15 @@ bool l2c_link_hci_conn_comp(uint8_t status, uint16_t handle,
   /* See if we have a link control block for the remote device */
   p_lcb = l2cu_find_lcb_by_bd_addr(ci.bd_addr, BT_TRANSPORT_BR_EDR);
 
-  /* If we don't have one, this is an error */
-  if (!p_lcb) {
-    L2CAP_TRACE_WARNING("L2CAP got conn_comp for unknown BD_ADDR");
-    return (false);
+  /* If we don't have one, allocate one */
+  if (p_lcb == nullptr) {
+    L2CAP_TRACE_WARNING("No available link control block, try allocate one");
+    p_lcb = l2cu_allocate_lcb(ci.bd_addr, false, BT_TRANSPORT_BR_EDR);
+    if (p_lcb == nullptr) {
+      L2CAP_TRACE_WARNING("%s: Failed to allocate an LCB", __func__);
+      return (false);
+    }
+    p_lcb->link_state = LST_CONNECTING;
   }
 
   if (p_lcb->link_state != LST_CONNECTING) {