This is an automated email from the ASF dual-hosted git repository.

rymek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 4931bbdccb9735cbf699531df40c7555de03fd7d
Author: Ɓukasz Rymanowski <[email protected]>
AuthorDate: Tue Jan 28 17:33:37 2020 +0100

    btshell: Add better handling on stalled CoC
---
 apps/btshell/src/btshell.h |  1 +
 apps/btshell/src/main.c    | 38 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/apps/btshell/src/btshell.h b/apps/btshell/src/btshell.h
index b7bb09e..7c97822 100644
--- a/apps/btshell/src/btshell.h
+++ b/apps/btshell/src/btshell.h
@@ -72,6 +72,7 @@ SLIST_HEAD(btshell_svc_list, btshell_svc);
 struct btshell_l2cap_coc {
     SLIST_ENTRY(btshell_l2cap_coc) next;
     struct ble_l2cap_chan *chan;
+    bool stalled;
 };
 
 SLIST_HEAD(btshell_l2cap_coc_list, btshell_l2cap_coc);
diff --git a/apps/btshell/src/main.c b/apps/btshell/src/main.c
index c7cfa33..b703183 100644
--- a/apps/btshell/src/main.c
+++ b/apps/btshell/src/main.c
@@ -2209,6 +2209,31 @@ btshell_l2cap_coc_accept(uint16_t conn_handle, uint16_t 
peer_mtu,
     return ble_l2cap_recv_ready(chan, sdu_rx);
 }
 
+static void
+btshell_l2cap_coc_unstalled(uint16_t conn_handle, struct ble_l2cap_chan *chan)
+{
+    struct btshell_conn *conn;
+    struct btshell_l2cap_coc *coc;
+    struct btshell_l2cap_coc *cur;
+
+    conn = btshell_conn_find(conn_handle);
+    assert(conn != NULL);
+
+    coc = NULL;
+    SLIST_FOREACH(cur, &conn->coc_list, next) {
+        if (cur->chan == chan) {
+            coc = cur;
+            break;
+        }
+    }
+
+    if (!coc) {
+        return;
+    }
+
+    coc->stalled = false;
+}
+
 static int
 btshell_l2cap_event(struct ble_l2cap_event *event, void *arg)
 {
@@ -2290,6 +2315,7 @@ btshell_l2cap_event(struct ble_l2cap_event *event, void 
*arg)
         case BLE_L2CAP_EVENT_COC_TX_UNSTALLED:
             console_printf("L2CAP CoC channel %p unstalled, last sdu sent with 
err=0x%02x\n",
                             event->tx_unstalled.chan, 
event->tx_unstalled.status);
+            btshell_l2cap_coc_unstalled(event->tx_unstalled.conn_handle, 
event->tx_unstalled.chan);
             return 0;
         default:
             return 0;
@@ -2457,6 +2483,11 @@ btshell_l2cap_send(uint16_t conn_handle, uint16_t idx, 
uint16_t bytes)
         return 0;
     }
 
+    if (coc->stalled) {
+        console_printf("Channel is stalled, wait ...\n");
+        return 0;
+    }
+
     sdu_tx = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
     if (sdu_tx == NULL) {
         console_printf("No memory in the test sdu pool\n");
@@ -2486,7 +2517,12 @@ btshell_l2cap_send(uint16_t conn_handle, uint16_t idx, 
uint16_t bytes)
 
     rc = ble_l2cap_send(coc->chan, sdu_tx);
     if (rc) {
-        console_printf("Could not send data rc=%d\n", rc);
+        if (rc == BLE_HS_ESTALLED) {
+          console_printf("CoC module is stalled with data. Wait for unstalled 
\n");
+          coc->stalled = true;
+        } else {
+            console_printf("Could not send data rc=%d\n", rc);
+        }
         os_mbuf_free_chain(sdu_tx);
     }
 

Reply via email to