Skip to content

Commit 089f0d8

Browse files
rymanluksjanc
authored andcommitted
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.
1 parent 75c745d commit 089f0d8

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

nimble/host/src/ble_l2cap_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ typedef int ble_l2cap_tx_fn(struct ble_hs_conn *conn,
105105
struct ble_l2cap_chan *chan);
106106

107107
#define BLE_L2CAP_CHAN_F_TXED_MTU 0x01 /* We have sent our MTU. */
108+
#define BLE_L2CAP_CHAN_F_DISCONNECTING 0x02 /* We have sent L2CAP Disconnect. */
108109

109110
SLIST_HEAD(ble_l2cap_chan_list, ble_l2cap_chan);
110111

nimble/host/src/ble_l2cap_sig.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,10 @@ ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
16401640
struct ble_l2cap_sig_proc *proc;
16411641
int rc;
16421642

1643+
if (chan->flags & BLE_L2CAP_CHAN_F_DISCONNECTING) {
1644+
return 0;
1645+
}
1646+
16431647
proc = ble_l2cap_sig_proc_alloc();
16441648
if (proc == NULL) {
16451649
return BLE_HS_ENOMEM;
@@ -1661,6 +1665,10 @@ ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
16611665
req->scid = htole16(chan->scid);
16621666

16631667
rc = ble_l2cap_sig_tx(proc->conn_handle, txom);
1668+
/* Mark channel as disconnecting */
1669+
if (rc == 0) {
1670+
chan->flags |= BLE_L2CAP_CHAN_F_DISCONNECTING;
1671+
}
16641672

16651673
done:
16661674
ble_l2cap_sig_process_status(proc, rc);

0 commit comments

Comments
 (0)