From 79e86472c3b6810b689a12f624c6d5ecdfff996b Mon Sep 17 00:00:00 2001 From: Jonathan Rico Date: Thu, 4 Jan 2024 09:55:47 +0100 Subject: [PATCH] Bluetooth: L2CAP: clarify BT_L2CAP_STATUS_OUT Makes it clearer what that bit means: If set, the channel has capacity to send at least one PDU. If unset, the channel ran out of credits and won't be able to send anything until the peer sends credits back. Also add debug logs. Signed-off-by: Jonathan Rico --- include/zephyr/bluetooth/l2cap.h | 2 +- subsys/bluetooth/host/l2cap.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/zephyr/bluetooth/l2cap.h b/include/zephyr/bluetooth/l2cap.h index d9241e7af2..3386c38bdb 100644 --- a/include/zephyr/bluetooth/l2cap.h +++ b/include/zephyr/bluetooth/l2cap.h @@ -120,7 +120,7 @@ typedef enum bt_l2cap_chan_state { /** @brief Status of L2CAP channel. */ typedef enum bt_l2cap_chan_status { - /** Channel output status */ + /** Channel can send at least one PDU */ BT_L2CAP_STATUS_OUT, /** @brief Channel shutdown status diff --git a/subsys/bluetooth/host/l2cap.c b/subsys/bluetooth/host/l2cap.c index 66c7038f3c..44a013f14b 100644 --- a/subsys/bluetooth/host/l2cap.c +++ b/subsys/bluetooth/host/l2cap.c @@ -973,9 +973,11 @@ static void l2cap_chan_tx_give_credits(struct bt_l2cap_le_chan *chan, atomic_add(&chan->tx.credits, credits); - if (!atomic_test_and_set_bit(chan->chan.status, BT_L2CAP_STATUS_OUT) && - chan->chan.ops->status) { - chan->chan.ops->status(&chan->chan, chan->chan.status); + if (!atomic_test_and_set_bit(chan->chan.status, BT_L2CAP_STATUS_OUT)) { + LOG_DBG("chan %p unpaused", chan); + if (chan->chan.ops->status) { + chan->chan.ops->status(&chan->chan, chan->chan.status); + } } } @@ -2045,11 +2047,11 @@ static int l2cap_chan_le_send(struct bt_l2cap_le_chan *ch, return err; } - /* Check if there is no credits left clear output status and notify its - * change. - */ + /* Notify channel user that it can't send anymore on this channel. */ if (!atomic_get(&ch->tx.credits)) { + LOG_DBG("chan %p paused", ch); atomic_clear_bit(ch->chan.status, BT_L2CAP_STATUS_OUT); + if (ch->chan.ops->status) { ch->chan.ops->status(&ch->chan, ch->chan.status); }