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

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


The following commit(s) were added to refs/heads/master by this push:
     new 089f0d8  l2cap: Fix double disconnect issue
089f0d8 is described below

commit 089f0d849a49a2a6c69f1e1f9103174b81af8b1a
Author: Ɓukasz Rymanowski <lukasz.rymanow...@codecoup.pl>
AuthorDate: Tue Mar 23 15:54:27 2021 +0100

    l2cap: Fix double disconnect issue
    
    It might happen that we get into situation that host will try to
    disconnect same channel couple times e.g when receiveing many
    corrupted packets.
    
    This patch make sure that host will send l2cap disconnect command only
    once.
---
 nimble/host/src/ble_l2cap_priv.h | 1 +
 nimble/host/src/ble_l2cap_sig.c  | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/nimble/host/src/ble_l2cap_priv.h b/nimble/host/src/ble_l2cap_priv.h
index e340974..21e6a8b 100644
--- a/nimble/host/src/ble_l2cap_priv.h
+++ b/nimble/host/src/ble_l2cap_priv.h
@@ -105,6 +105,7 @@ typedef int ble_l2cap_tx_fn(struct ble_hs_conn *conn,
                             struct ble_l2cap_chan *chan);
 
 #define BLE_L2CAP_CHAN_F_TXED_MTU       0x01    /* We have sent our MTU. */
+#define BLE_L2CAP_CHAN_F_DISCONNECTING  0x02    /* We have sent L2CAP 
Disconnect. */
 
 SLIST_HEAD(ble_l2cap_chan_list, ble_l2cap_chan);
 
diff --git a/nimble/host/src/ble_l2cap_sig.c b/nimble/host/src/ble_l2cap_sig.c
index 02f805f..aaf9c64 100644
--- a/nimble/host/src/ble_l2cap_sig.c
+++ b/nimble/host/src/ble_l2cap_sig.c
@@ -1640,6 +1640,10 @@ ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
     struct ble_l2cap_sig_proc *proc;
     int rc;
 
+    if (chan->flags & BLE_L2CAP_CHAN_F_DISCONNECTING) {
+        return 0;
+    }
+
     proc = ble_l2cap_sig_proc_alloc();
     if (proc == NULL) {
         return BLE_HS_ENOMEM;
@@ -1661,6 +1665,10 @@ ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
     req->scid = htole16(chan->scid);
 
     rc = ble_l2cap_sig_tx(proc->conn_handle, txom);
+    /* Mark channel as disconnecting */
+    if (rc == 0) {
+        chan->flags |= BLE_L2CAP_CHAN_F_DISCONNECTING;
+    }
 
 done:
     ble_l2cap_sig_process_status(proc, rc);

Reply via email to