Skip to content
Permalink
Browse files

Bluetooth: L2CAP: Add sent callback

This adds a new callback to bt_l2cap_chan_ops which is called whenever a
SDU is completely sent.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
  • Loading branch information...
Vudentz authored and jhedberg committed May 21, 2019
1 parent b65fe62 commit d8f20fe1e0b0ca698185fbad4dd8467ea8931c06
Showing with 33 additions and 4 deletions.
  1. +9 −0 include/bluetooth/l2cap.h
  2. +24 −4 subsys/bluetooth/host/l2cap.c
@@ -211,6 +211,15 @@ struct bt_l2cap_chan_ops {
* number of segments/credits used by the packet.
*/
int (*recv)(struct bt_l2cap_chan *chan, struct net_buf *buf);

/* Channel sent callback
*
* If this callback is provided it will be called whenever a SDU has
* been completely sent.
*
* @param chan The channel which has sent data.
*/
void (*sent)(struct bt_l2cap_chan *chan);
};

/** @def BT_L2CAP_CHAN_SEND_RESERVE
@@ -1097,9 +1097,21 @@ static struct net_buf *l2cap_chan_create_seg(struct bt_l2cap_le_chan *ch,
return seg;
}

static void l2cap_chan_sdu_sent(struct bt_conn *conn, void *user_data)
{
struct bt_l2cap_chan *chan = user_data;

BT_DBG("conn %p chan %p", conn, chan);

if (chan->ops->sent) {
chan->ops->sent(chan);
}
}

static int l2cap_chan_le_send(struct bt_l2cap_le_chan *ch, struct net_buf *buf,
u16_t sdu_hdr_len)
{
struct net_buf *seg;
int len;

/* Wait for credits */
@@ -1108,7 +1120,7 @@ static int l2cap_chan_le_send(struct bt_l2cap_le_chan *ch, struct net_buf *buf,
return -EAGAIN;
}

buf = l2cap_chan_create_seg(ch, buf, sdu_hdr_len);
seg = l2cap_chan_create_seg(ch, buf, sdu_hdr_len);

/* Channel may have been disconnected while waiting for a buffer */
if (!ch->chan.conn) {
@@ -1117,11 +1129,19 @@ static int l2cap_chan_le_send(struct bt_l2cap_le_chan *ch, struct net_buf *buf,
}

BT_DBG("ch %p cid 0x%04x len %u credits %u", ch, ch->tx.cid,
buf->len, k_sem_count_get(&ch->tx.credits));
seg->len, k_sem_count_get(&ch->tx.credits));

len = buf->len - sdu_hdr_len;
len = seg->len - sdu_hdr_len;

bt_l2cap_send(ch->chan.conn, ch->tx.cid, buf);
/* Set a callback if there is no data left in the buffer and sent
* callback has been set.
*/
if ((buf == seg || !buf->len) && ch->chan.ops->sent) {
bt_l2cap_send_cb(ch->chan.conn, ch->tx.cid, seg,
l2cap_chan_sdu_sent, &ch->chan);
} else {
bt_l2cap_send(ch->chan.conn, ch->tx.cid, seg);
}

return len;
}

0 comments on commit d8f20fe

Please sign in to comment.
You can’t perform that action at this time.