From 48dd0f38255f755c9de1b2fc4b685514a0005c49 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 3 Apr 2018 17:23:54 -0600 Subject: [PATCH] wireless/bluetooth: Fix some confusion in initialization of message queues. --- drivers/wireless/bluetooth/bt_null.c | 25 +++++++++++++++++-------- wireless/bluetooth/bt_buf.c | 2 -- wireless/bluetooth/bt_hcicore.c | 15 ++++++++------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/drivers/wireless/bluetooth/bt_null.c b/drivers/wireless/bluetooth/bt_null.c index 512bd21bfe..66908dcfad 100644 --- a/drivers/wireless/bluetooth/bt_null.c +++ b/drivers/wireless/bluetooth/bt_null.c @@ -50,7 +50,8 @@ * Private Function Prototypes ****************************************************************************/ -static void btnull_send_cmdcomplete(FAR const struct bt_driver_s *dev); +static void btnull_send_cmdcomplete(FAR const struct bt_driver_s *dev, + uint16_t opcode); static int btnull_open(FAR const struct bt_driver_s *dev); static int btnull_send(FAR const struct bt_driver_s *dev, @@ -71,21 +72,29 @@ static const struct bt_driver_s g_bt_null = * Private Functions ****************************************************************************/ -static void btnull_send_cmdcomplete(FAR const struct bt_driver_s *dev) +static void btnull_send_cmdcomplete(FAR const struct bt_driver_s *dev, + uint16_t opcode) { FAR struct bt_buf_s *buf; buf = bt_buf_alloc(BT_EVT, NULL, 0); if (buf != NULL) { - FAR struct bt_hci_evt_hdr_s hdr; + struct bt_hci_evt_hdr_s evt; + struct hci_evt_cmd_complete_s cmd; /* Minimal setup for the command complete event */ - hdr.evt = BT_HCI_EVT_CMD_COMPLETE; - hdr.len = sizeof(struct bt_hci_evt_hdr_s); - memcpy(bt_buf_extend(buf, sizeof(struct bt_hci_evt_hdr_s)), &hdr, - sizeof(struct bt_hci_evt_hdr_s)); + evt.evt = BT_HCI_EVT_CMD_COMPLETE; + evt.len = sizeof(struct bt_hci_evt_hdr_s) + + sizeof(struct hci_evt_cmd_complete_s); + memcpy(bt_buf_extend(buf, sizeof(struct bt_hci_evt_hdr_s)), &evt, + sizeof(struct bt_hci_evt_hdr_s)); + + cmd.ncmd = 1; + cmd.opcode = opcode; + memcpy(bt_buf_extend(buf, sizeof(struct hci_evt_cmd_complete_s)), + &cmd, sizeof(struct hci_evt_cmd_complete_s)); wlinfo("Send CMD complete event\n"); @@ -105,7 +114,7 @@ static int btnull_send(FAR const struct bt_driver_s *dev, FAR struct bt_hci_cmd_hdr_s *hdr = (FAR void *)buf->data; wlinfo("CMD: %04x\n", hdr->opcode); - btnull_send_cmdcomplete(dev); + btnull_send_cmdcomplete(dev, hdr->opcode); } return buf->len; diff --git a/wireless/bluetooth/bt_buf.c b/wireless/bluetooth/bt_buf.c index ac3c787985..7ba8a4f043 100644 --- a/wireless/bluetooth/bt_buf.c +++ b/wireless/bluetooth/bt_buf.c @@ -363,9 +363,7 @@ FAR struct bt_buf_s *bt_buf_alloc(enum bt_buf_type_e type, buf->data = buf->frame->io_data + reserve_head; } - wlinfo("buf %p type %d reserve %u\n", buf, buf->type, reserve_head); - return buf; } diff --git a/wireless/bluetooth/bt_hcicore.c b/wireless/bluetooth/bt_hcicore.c index d5b8c358f3..7e952be399 100644 --- a/wireless/bluetooth/bt_hcicore.c +++ b/wireless/bluetooth/bt_hcicore.c @@ -248,7 +248,7 @@ static void hci_cmd_complete(FAR struct bt_buf_s *buf) uint16_t opcode = BT_LE162HOST(evt->opcode); FAR uint8_t *status; - wlinfo("opcode %x\n", opcode); + wlinfo("opcode %04x\n", opcode); bt_buf_consume(buf, sizeof(*evt)); @@ -271,7 +271,7 @@ static void hci_cmd_complete(FAR struct bt_buf_s *buf) hci_cmd_done(opcode, *status, buf); - if (evt->ncmd && !g_btdev.ncmd) + if (evt->ncmd > 0 && g_btdev.ncmd == 0) { /* Allow next command to be sent */ @@ -801,7 +801,7 @@ static void hci_event(FAR struct bt_buf_s *buf) wlinfo("event %u\n", hdr->evt); - bt_buf_consume(buf, sizeof(*hdr)); + bt_buf_consume(buf, sizeof(struct bt_hci_evt_hdr_s)); switch (hdr->evt) { @@ -1186,8 +1186,8 @@ static void cmd_queue_init(void) */ g_btdev.tx_queue = NULL; - ret = bt_queue_open(BT_HCI_RX, O_RDWR | O_CREAT, - CONFIG_BLUETOOTH_RXTHREAD_NMSGS, &g_btdev.tx_queue); + ret = bt_queue_open(BT_HCI_TX, O_RDWR | O_CREAT, + CONFIG_BLUETOOTH_TXCMD_NMSGS, &g_btdev.tx_queue); DEBUGASSERT(ret >= 0 && g_btdev.tx_queue != NULL); UNUSED(ret); @@ -1213,7 +1213,7 @@ static void rx_queue_init(void) g_btdev.rx_queue = NULL; ret = bt_queue_open(BT_HCI_RX, O_RDWR | O_CREAT, - CONFIG_BLUETOOTH_TXCMD_NMSGS, &g_btdev.rx_queue); + CONFIG_BLUETOOTH_RXTHREAD_NMSGS, &g_btdev.rx_queue); DEBUGASSERT(ret >= 0 && g_btdev.rx_queue != NULL); UNUSED(ret); @@ -1410,7 +1410,8 @@ FAR struct bt_buf_s *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len) int bt_hci_cmd_send(uint16_t opcode, FAR struct bt_buf_s *buf) { int ret; - if (!buf) + + if (buf == NULL) { buf = bt_hci_cmd_create(opcode, 0); if (!buf)