Bluetooth: Refactor ACL PDU creation to prepare for fragmentation

There's no point in encoding the ACL header in bt_conn_create_pdu()
since ultimately we might end up having to split the data into
multiple buffers - each with their own ACL header. Instead, move the
header encoding into bt_conn_send() where we can later add the proper
fragmentation support.

Change-Id: I84ac35161fc31bbd0a92391ec920224da69f43e1
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2015-05-05 11:06:54 +03:00 committed by Anas Nashif
commit d14c9c176f
3 changed files with 12 additions and 16 deletions

View file

@ -147,8 +147,15 @@ void bt_conn_recv(struct bt_conn *conn, struct bt_buf *buf, uint8_t flags)
void bt_conn_send(struct bt_conn *conn, struct bt_buf *buf)
{
struct bt_hci_acl_hdr *hdr;
uint16_t len = buf->len;
BT_DBG("conn handle %u buf len %u\n", conn->handle, buf->len);
hdr = (void *)bt_buf_push(buf, sizeof(*hdr));
hdr->handle = sys_cpu_to_le16(conn->handle);
hdr->len = sys_cpu_to_le16(len);
nano_fifo_put(&conn->tx_queue, buf);
}
@ -308,20 +315,9 @@ void bt_conn_put(struct bt_conn *conn)
conn->handle = 0;
}
struct bt_buf *bt_conn_create_pdu(struct bt_conn *conn, size_t len)
struct bt_buf *bt_conn_create_pdu(struct bt_conn *conn)
{
struct bt_dev *dev = conn->dev;
struct bt_hci_acl_hdr *hdr;
struct bt_buf *buf;
size_t reserve = conn->dev->drv->head_reserve;
buf = bt_buf_get(BT_ACL_OUT, dev->drv->head_reserve);
if (!buf) {
return NULL;
}
hdr = (void *)bt_buf_add(buf, sizeof(*hdr));
hdr->handle = sys_cpu_to_le16(conn->handle);
hdr->len = len;
return buf;
return bt_buf_get(BT_ACL_OUT, reserve + sizeof(struct bt_hci_acl_hdr));
}

View file

@ -62,7 +62,7 @@ struct bt_conn {
};
/* Prepare a new buffer to be sent over the connection */
struct bt_buf *bt_conn_create_pdu(struct bt_conn *conn, size_t len);
struct bt_buf *bt_conn_create_pdu(struct bt_conn *conn);
/* Process incoming data for a connection */
void bt_conn_recv(struct bt_conn *conn, struct bt_buf *buf, uint8_t flags);

View file

@ -35,7 +35,7 @@ struct bt_buf *bt_l2cap_create_pdu(struct bt_conn *conn, uint16_t cid,
struct bt_l2cap_hdr *hdr;
struct bt_buf *buf;
buf = bt_conn_create_pdu(conn, sizeof(*hdr) + len);
buf = bt_conn_create_pdu(conn);
if (!buf) {
return NULL;
}