Exemplo n.º 1
0
int bt_l2cap_chan_send(struct bt_l2cap_chan *chan, struct net_buf *buf)
{
	int err;

	if (!buf) {
		return -EINVAL;
	}

	BT_DBG("chan %p buf %p len %u", chan, buf, buf->len);

	if (!chan->conn || chan->conn->state != BT_CONN_CONNECTED) {
		return -ENOTCONN;
	}

	if (IS_ENABLED(CONFIG_BLUETOOTH_BREDR) &&
	    chan->conn->type == BT_CONN_TYPE_BR) {
		return bt_l2cap_br_chan_send(chan, buf);
	}

	err = l2cap_chan_le_send_sdu(BT_L2CAP_LE_CHAN(chan), buf, 0);
	if (err < 0) {
		if (err == -EAGAIN) {
			/* Queue buffer to be sent later */
			net_buf_put(&(BT_L2CAP_LE_CHAN(chan))->tx_queue, buf);
			return *((int *)net_buf_user_data(buf));
		}
		BT_ERR("failed to send message %d", err);
	}

	return err;
}
Exemplo n.º 2
0
int bt_l2cap_chan_send(struct bt_l2cap_chan *chan, struct net_buf *buf)
{
	int err;

	if (!buf) {
		return -EINVAL;
	}

	BT_DBG("chan %p buf %p len %u", chan, buf, buf->len);

	if (!chan->conn || chan->conn->state != BT_CONN_CONNECTED) {
		return -ENOTCONN;
	}

#if defined(CONFIG_BLUETOOTH_BREDR)
	if (chan->conn->type == BT_CONN_TYPE_BR) {
		return bt_l2cap_br_chan_send(chan, buf);
	}
#endif /* CONFIG_BLUETOOTH_BREDR */

	err = l2cap_chan_le_send_sdu(LE_CHAN(chan), buf);
	if (err < 0) {
		BT_ERR("failed to send message %d", err);
	}

	return err;
}
Exemplo n.º 3
0
static void l2cap_chan_le_send_resume(struct bt_l2cap_le_chan *ch)
{
	struct net_buf *buf;

	/* Resume tx in case there are buffers in the queue */
	while ((buf = l2cap_chan_le_get_tx_buf(ch))) {
		int sent = *((int *)net_buf_user_data(buf));

		BT_DBG("buf %p sent %u", buf, sent);

		sent = l2cap_chan_le_send_sdu(ch, buf, sent);
		if (sent < 0) {
			if (sent == -EAGAIN) {
				ch->tx_buf = buf;
			}
			break;
		}
	}
}