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

Commit 9c751d23 authored by Chienyuan's avatar Chienyuan
Browse files

Allocate lcb when connection complete if can't find one

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
parent c8b997e3
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -159,11 +159,16 @@ 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");
  /* 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) {
    L2CAP_TRACE_ERROR("L2CAP got conn_comp in bad state: %d  status: 0x%d",