diff --git a/net/bluetooth/conn.c b/net/bluetooth/conn.c index ee5a7122310..75c37556d93 100644 --- a/net/bluetooth/conn.c +++ b/net/bluetooth/conn.c @@ -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)); } diff --git a/net/bluetooth/conn.h b/net/bluetooth/conn.h index 0b5ffb261c2..311e44e08de 100644 --- a/net/bluetooth/conn.h +++ b/net/bluetooth/conn.h @@ -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); diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c index 8b6493b02f9..82b45132969 100644 --- a/net/bluetooth/l2cap.c +++ b/net/bluetooth/l2cap.c @@ -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; }