Bluetooth: Refactor buffer HCI user data

To accommodate for ACL user data move the HCI command/event data into
its own struct and put it inside a union in bt_buf.

Change-Id: I680500b15709d14b1e9f70ced88664d607a6568c
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2015-04-28 15:18:13 +03:00 committed by Anas Nashif
commit 5626788eb7
3 changed files with 19 additions and 10 deletions

View file

@ -48,13 +48,19 @@ enum bt_buf_type {
BT_ACL_IN, /* Incoming ACL data */ BT_ACL_IN, /* Incoming ACL data */
}; };
/* HCI command specific info */
struct bt_buf_hci_data {
struct nano_sem *sync;
uint16_t opcode;
};
struct bt_buf { struct bt_buf {
/* FIFO uses first 4 bytes itself, reserve space */ /* FIFO uses first 4 bytes itself, reserve space */
int __unused; int __unused;
/* HCI command specific info */ union {
struct nano_sem *sync; struct bt_buf_hci_data hci;
uint16_t opcode; };
/* Type of data contained in the buffer */ /* Type of data contained in the buffer */
uint8_t type; uint8_t type;

View file

@ -79,7 +79,7 @@ struct bt_buf *bt_buf_get(enum bt_buf_type type, size_t reserve_head)
buf->type = type; buf->type = type;
buf->data = buf->buf + reserve_head; buf->data = buf->buf + reserve_head;
buf->len = 0; buf->len = 0;
buf->sync = NULL; buf->hci.sync = NULL;
BT_DBG("buf %p reserve %u\n", buf, reserve_head); BT_DBG("buf %p reserve %u\n", buf, reserve_head);

View file

@ -69,8 +69,8 @@ struct bt_buf *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
BT_DBG("buf %p\n", buf); BT_DBG("buf %p\n", buf);
buf->opcode = opcode; buf->hci.opcode = opcode;
buf->sync = NULL; buf->hci.sync = NULL;
hdr = (void *)bt_buf_add(buf, sizeof(*hdr)); hdr = (void *)bt_buf_add(buf, sizeof(*hdr));
hdr->opcode = sys_cpu_to_le16(opcode); hdr->opcode = sys_cpu_to_le16(opcode);
@ -107,7 +107,7 @@ static int bt_hci_cmd_send_sync(uint16_t opcode, struct bt_buf *buf)
BT_DBG("opcode %x len %u\n", opcode, buf->len); BT_DBG("opcode %x len %u\n", opcode, buf->len);
nano_sem_init(&sync_sem); nano_sem_init(&sync_sem);
buf->sync = &sync_sem; buf->hci.sync = &sync_sem;
nano_fifo_put(&dev.cmd_queue, buf); nano_fifo_put(&dev.cmd_queue, buf);
@ -265,7 +265,10 @@ static void hci_cmd_done(uint16_t opcode)
{ {
struct bt_buf *sent = dev.sent_cmd; struct bt_buf *sent = dev.sent_cmd;
if (dev.sent_cmd->opcode != opcode) { if (!sent)
return;
if (dev.sent_cmd->hci.opcode != opcode) {
BT_ERR("Unexpected completion of opcode %x\n", opcode); BT_ERR("Unexpected completion of opcode %x\n", opcode);
return; return;
} }
@ -273,8 +276,8 @@ static void hci_cmd_done(uint16_t opcode)
dev.sent_cmd = NULL; dev.sent_cmd = NULL;
/* If the command was synchronous wake up bt_hci_cmd_send_sync() */ /* If the command was synchronous wake up bt_hci_cmd_send_sync() */
if (sent->sync) if (sent->hci.sync)
nano_fiber_sem_give(sent->sync); nano_fiber_sem_give(sent->hci.sync);
bt_buf_put(sent); bt_buf_put(sent);
} }