From 6c7a387e9f404f9beaeb883bdf977c5852b615dc Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Tue, 28 Jul 2020 10:07:48 -0700 Subject: [PATCH] Bluetooth: ATT: Fix handling to EATT channels EATT channels use bt_l2cap_chan_send which does return the number of bytes sent on success not 0 as bt_l2cap_send. Signed-off-by: Luiz Augusto von Dentz --- subsys/bluetooth/host/att.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/subsys/bluetooth/host/att.c b/subsys/bluetooth/host/att.c index 74254e1cc93e..875db533dca7 100644 --- a/subsys/bluetooth/host/att.c +++ b/subsys/bluetooth/host/att.c @@ -154,6 +154,8 @@ static int chan_send(struct bt_att_chan *chan, struct net_buf *buf, if (IS_ENABLED(CONFIG_BT_EATT) && atomic_test_bit(chan->flags, ATT_ENHANCED)) { + int err; + /* Check if sent is pending already, if it does it cannot be * modified so the operation will need to be queued. */ @@ -174,7 +176,15 @@ static int chan_send(struct bt_att_chan *chan, struct net_buf *buf, return -EAGAIN; } - return bt_l2cap_chan_send(&chan->chan.chan, buf); + /* bt_l2cap_chan_send does actually return the number of bytes + * that could be sent immediatelly. + */ + err = bt_l2cap_chan_send(&chan->chan.chan, buf); + if (err < 0) { + return err; + } + + return 0; } if (hdr->code == BT_ATT_OP_SIGNED_WRITE_CMD) { @@ -233,7 +243,7 @@ static int chan_req_send(struct bt_att_chan *chan, struct bt_att_req *req) /* Keep a reference for resending in case of an error */ err = chan_send(chan, net_buf_ref(req->buf), NULL); - if (err < 0) { + if (err) { net_buf_unref(req->buf); chan->req = NULL; }