From 0ca073c7f4728aeb900e2e0a3d3942bdbe5bdb24 Mon Sep 17 00:00:00 2001 From: Sumeet Singh Date: Tue, 29 Oct 2024 19:23:36 +0530 Subject: [PATCH] feat(nimble): Added option to disable automatically sending extra credits to peer --- nimble/host/src/ble_l2cap_coc.c | 4 ++-- nimble/host/src/ble_l2cap_priv.h | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/nimble/host/src/ble_l2cap_coc.c b/nimble/host/src/ble_l2cap_coc.c index f7b01a4af..2ae77a235 100644 --- a/nimble/host/src/ble_l2cap_coc.c +++ b/nimble/host/src/ble_l2cap_coc.c @@ -283,7 +283,7 @@ ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan) * However, we still have buffer to for next LE Frame so lets give one more * credit to peer so it can send us full SDU */ - if (rx->credits == 0) { + if (chan->disable_auto_credit_update == false && rx->credits == 0) { /* Remote did not send full SDU. Lets give him one more credits to do * so since we have still buffer to handle it */ @@ -598,7 +598,7 @@ ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx) /* We want to back only that much credits which remote side is missing * to be able to send complete SDU. */ - if (chan->coc_rx.credits < c->initial_credits) { + if (chan->disable_auto_credit_update == false && chan->coc_rx.credits < c->initial_credits) { ble_hs_unlock(); ble_l2cap_sig_le_credits(chan->conn_handle, chan->scid, c->initial_credits - chan->coc_rx.credits); diff --git a/nimble/host/src/ble_l2cap_priv.h b/nimble/host/src/ble_l2cap_priv.h index 128afeed1..08ad3b3e8 100644 --- a/nimble/host/src/ble_l2cap_priv.h +++ b/nimble/host/src/ble_l2cap_priv.h @@ -92,6 +92,19 @@ struct ble_l2cap_chan { struct ble_l2cap_coc_endpoint coc_rx; struct ble_l2cap_coc_endpoint coc_tx; uint16_t initial_credits; +/** + * Disable automatically sending credits to a remote + * + * This field disables automatically sending extra credit to a + * remote that has exhausted all of its available credits. + * Setting this field to "true" will enable behaviour to + * "not automatically send credits to a peer whose credits are exhausted" + * Setting this field to "false" will enable behaviour to + * "automatically send credits to a peer whose credits are exhausted" + * this behaviour. + * + */ + bool disable_auto_credit_update; ble_l2cap_event_fn *cb; void *cb_arg; #endif