wireless/bluetooth: Fix some confusion in initialization of message queues.

This commit is contained in:
Gregory Nutt 2018-04-03 17:23:54 -06:00
parent 265b5d7dc6
commit 48dd0f3825
3 changed files with 25 additions and 17 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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)