From 98657a365c7230b84a005c63ce5bcf036d69f6eb Mon Sep 17 00:00:00 2001
From: Andre Eisenbach <andre@broadcom.com>
Date: Tue, 25 Jun 2013 16:44:56 -0700
Subject: [PATCH] LE: Release transmit buffer credits

When an ACL link goes down, some controllers do not send a "number of
completed packets" update for the last ACL packets sent from the host to
the controller. This could result in incorrect L2CAP transmit window
calculations and no transmit credit to be available to send data to the
controller.
This patch restores transmit buffer creedits regardless of the
controller behaviour.
bug 9474159

Change-Id: I2540131034271a0269fa50698f370bceb7747e2d
---
 stack/l2cap/l2c_utils.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/stack/l2cap/l2c_utils.c b/stack/l2cap/l2c_utils.c
index b911db2..457ea2d 100644
--- a/stack/l2cap/l2c_utils.c
+++ b/stack/l2cap/l2c_utils.c
@@ -136,6 +136,28 @@ void l2cu_release_lcb (tL2C_LCB *p_lcb)
     btm_remove_sco_links(p_lcb->remote_bd_addr);
 #endif
 
+    if (p_lcb->sent_not_acked > 0)
+    {
+#if (BLE_INCLUDED == TRUE)
+        if (p_lcb->is_ble_link)
+        {
+            l2cb.controller_le_xmit_window += p_lcb->sent_not_acked;
+            if (l2cb.controller_le_xmit_window > l2cb.num_lm_ble_bufs)
+            {
+                l2cb.controller_le_xmit_window = l2cb.num_lm_ble_bufs;
+            }
+        }
+        else
+#endif
+        {
+            l2cb.controller_xmit_window += p_lcb->sent_not_acked;
+            if (l2cb.controller_xmit_window > l2cb.num_lm_acl_bufs)
+            {
+                l2cb.controller_xmit_window = l2cb.num_lm_acl_bufs;
+            }
+        }
+    }
+
 #if (BLE_INCLUDED == TRUE)
     p_lcb->is_ble_link = FALSE;
     l2cb.is_ble_connecting = FALSE;
@@ -183,15 +205,6 @@ void l2cu_release_lcb (tL2C_LCB *p_lcb)
     if (l2cb.num_links_active >= 1)
         l2cb.num_links_active--;
 
-    if (p_lcb->sent_not_acked > 0)
-    {
-        l2cb.controller_xmit_window += p_lcb->sent_not_acked;
-        if (l2cb.controller_xmit_window > l2cb.num_lm_acl_bufs)
-        {
-            l2cb.controller_xmit_window = l2cb.num_lm_acl_bufs;
-        }
-    }
-
     l2c_link_adjust_allocation();
 
     /* Check for ping outstanding */
-- 
GitLab