diff --git a/nimble/host/src/ble_l2cap_priv.h b/nimble/host/src/ble_l2cap_priv.h index e3409743b..21e6a8bf6 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 02f805f5d..aaf9c642a 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);