예제 #1
0
파일: l2cap.c 프로젝트: hudkmr/zephyr
static int l2cap_chan_le_send_sdu(struct bt_l2cap_le_chan *ch,
				  struct net_buf *buf)
{
	int ret, sent, total_len;

	if (buf->len > ch->tx.mtu) {
		return -EMSGSIZE;
	}

	total_len = buf->len;

	/* Add SDU length for the first segment */
	ret = l2cap_chan_le_send(ch, buf, BT_L2CAP_SDU_HDR_LEN);
	if (ret < 0) {
		return ret;
	}

	/* Send remaining segments */
	for (sent = ret; sent < total_len; sent += ret) {
		ret = l2cap_chan_le_send(ch, buf, 0);
		if (ret < 0) {
			return ret;
		}
	}

	BT_DBG("ch %p cid 0x%04x sent %u", ch, ch->tx.cid, sent);

	net_buf_unref(buf);

	return sent;
}
예제 #2
0
파일: l2cap.c 프로젝트: cyysu/AliOS-Things
static int l2cap_chan_le_send_sdu(struct bt_l2cap_le_chan *ch,
				  struct net_buf *buf, int sent)
{
	int ret, total_len;
	struct net_buf *frag;

	total_len = net_buf_frags_len(buf) + sent;

	if (total_len > ch->tx.mtu) {
		return -EMSGSIZE;
	}

	frag = buf;
	if (!frag->len && frag->frags) {
		frag = frag->frags;
	}

	if (!sent) {
		/* Add SDU length for the first segment */
		sent = l2cap_chan_le_send(ch, frag, BT_L2CAP_SDU_HDR_LEN);
		if (sent < 0) {
			if (sent == -EAGAIN) {
				sent = 0;
				/* Store sent data into user_data */
				memcpy(net_buf_user_data(buf), &sent,
				       sizeof(sent));
			}
			return sent;
		}
	}

	/* Send remaining segments */
	for (ret = 0; sent < total_len; sent += ret) {
		/* Proceed to next fragment */
		if (!frag->len) {
			frag = net_buf_frag_del(buf, frag);
		}

		ret = l2cap_chan_le_send(ch, frag, 0);
		if (ret < 0) {
			if (ret == -EAGAIN) {
				/* Store sent data into user_data */
				memcpy(net_buf_user_data(buf), &sent,
				       sizeof(sent));
			}
			return ret;
		}
	}

	BT_DBG("ch %p cid 0x%04x sent %u", ch, ch->tx.cid, sent);

	net_buf_unref(buf);

	return ret;
}