drivers/wireless: Add option to dump I/O buffers. Fix calculation of response length.

This commit is contained in:
Gregory Nutt 2018-04-18 12:46:47 -06:00
parent 50ca22ae78
commit 8ab2eb55d6
3 changed files with 38 additions and 17 deletions

View File

@ -48,6 +48,13 @@ config BLUETOOTH_UART
---help--- ---help---
Enable Bluetooth UART driver. Enable Bluetooth UART driver.
config BLUETOOTH_UART_DUMP
bool "Dump HCI UART I/O buffers"
default n
depends on BLUETOOTH_UART && DEBUG_WIRELESS_INFO
---help---
Dump the full content of all outgoing and incoming messages.
config BLUETOOTH_NULL config BLUETOOTH_NULL
bool "NULL Bluetooth device" bool "NULL Bluetooth device"
default n default n

View File

@ -62,10 +62,16 @@
#define H4_HEADER_SIZE 1 #define H4_HEADER_SIZE 1
#define H4_CMD 0x01 #define H4_CMD 0x01
#define H4_ACL 0x02 #define H4_ACL 0x02
#define H4_SCO 0x03 #define H4_SCO 0x03
#define H4_EVT 0x04 #define H4_EVT 0x04
#ifdef CONFIG_BLUETOOTH_UART_DUMP
# define BT_DUMP(m,b,l) lib_dumpbuffer(m,b,l)
#else
# define BT_DUMP(m,b,l)
#endif
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
@ -265,8 +271,8 @@ static void btuart_rxwork(FAR void *arg)
goto errout_with_buf; goto errout_with_buf;
} }
remaining = hdrlen - 1; remaining = hdrlen;
wlinfo("Need to get %u of %u bytes\n", remaining, hdrlen); wlinfo("Need to get %u bytes\n", remaining);
while (remaining > 0) while (remaining > 0)
{ {
@ -282,11 +288,16 @@ static void btuart_rxwork(FAR void *arg)
/* Drain any un-read bytes from the Rx buffer */ /* Drain any un-read bytes from the Rx buffer */
nread = lower->rxdrain(lower); nread = lower->rxdrain(lower);
wlwarn("WARNING: Discarded %ld bytes\n", (long)nread); if (nread > 0)
{
wlwarn("WARNING: Discarded %ld bytes\n", (long)nread);
}
/* Pass buffer to the stack */ /* Pass buffer to the stack */
upper->busy = false; upper->busy = false;
BT_DUMP("Received", buf->data, buf->len);
bt_hci_receive(buf); bt_hci_receive(buf);
return; return;
@ -359,6 +370,8 @@ static int btuart_send(FAR const struct bt_driver_s *dev,
return -EINVAL; return -EINVAL;
} }
BT_DUMP("Sending", buf->data, buf->len);
nwritten = lower->write(lower, buf->data, buf->len); nwritten = lower->write(lower, buf->data, buf->len);
if (nwritten == buf->len) if (nwritten == buf->len)
{ {

View File

@ -238,6 +238,7 @@ static void hci_cmd_done(uint16_t opcode, uint8_t status,
if (status != 0) if (status != 0)
{ {
wlwarn("WARNING: status %u\n", status);
sent->u.hci.sync = NULL; sent->u.hci.sync = NULL;
} }
else else
@ -276,7 +277,7 @@ static void hci_cmd_complete(FAR struct bt_buf_s *buf)
break; break;
default: default:
wlinfo("Unhandled opcode %x\n", opcode); wlinfo("Unhandled opcode %04x\n", opcode);
break; break;
} }
@ -296,14 +297,14 @@ static void hci_cmd_status(FAR struct bt_buf_s *buf)
FAR struct bt_hci_evt_cmd_status_s *evt = (FAR void *)buf->data; FAR struct bt_hci_evt_cmd_status_s *evt = (FAR void *)buf->data;
uint16_t opcode = BT_LE162HOST(evt->opcode); uint16_t opcode = BT_LE162HOST(evt->opcode);
wlinfo("opcode %x\n", opcode); wlinfo("opcode %04x\n", opcode);
bt_buf_consume(buf, sizeof(*evt)); bt_buf_consume(buf, sizeof(*evt));
switch (opcode) switch (opcode)
{ {
default: default:
wlinfo("Unhandled opcode %x\n", opcode); wlinfo("Unhandled opcode %04x\n", opcode);
break; break;
} }
@ -810,7 +811,7 @@ static void hci_le_meta_event(FAR struct bt_buf_s *buf)
break; break;
default: default:
wlinfo("Unhandled LE event %x\n", evt->subevent); wlinfo("Unhandled LE event %04x\n", evt->subevent);
break; break;
} }
} }
@ -1131,8 +1132,8 @@ static int hci_initialize(void)
hbs = bt_buf_extend(buf, sizeof(*hbs)); hbs = bt_buf_extend(buf, sizeof(*hbs));
memset(hbs, 0, sizeof(*hbs)); memset(hbs, 0, sizeof(*hbs));
hbs->acl_mtu = BT_HOST2LE16(BLUETOOTH_MAX_FRAMELEN - hbs->acl_mtu = BT_HOST2LE16(BLUETOOTH_MAX_FRAMELEN -
sizeof(struct bt_hci_acl_hdr_s) - sizeof(struct bt_hci_acl_hdr_s) -
g_btdev.btdev->head_reserve); g_btdev.btdev->head_reserve);
hbs->acl_pkts = BT_HOST2LE16(CONFIG_BLUETOOTH_RXTHREAD_NMSGS); hbs->acl_pkts = BT_HOST2LE16(CONFIG_BLUETOOTH_RXTHREAD_NMSGS);
ret = bt_hci_cmd_send(BT_HCI_OP_HOST_BUFFER_SIZE, buf); ret = bt_hci_cmd_send(BT_HCI_OP_HOST_BUFFER_SIZE, buf);
@ -1424,7 +1425,7 @@ FAR struct bt_buf_s *bt_hci_cmd_create(uint16_t opcode, uint8_t param_len)
FAR struct bt_hci_cmd_hdr_s *hdr; FAR struct bt_hci_cmd_hdr_s *hdr;
FAR struct bt_buf_s *buf; FAR struct bt_buf_s *buf;
wlinfo("opcode %x param_len %u\n", opcode, param_len); wlinfo("opcode %04x param_len %u\n", opcode, param_len);
buf = bt_buf_alloc(BT_CMD, NULL, g_btdev.btdev->head_reserve); buf = bt_buf_alloc(BT_CMD, NULL, g_btdev.btdev->head_reserve);
if (!buf) if (!buf)
@ -1459,7 +1460,7 @@ int bt_hci_cmd_send(uint16_t opcode, FAR struct bt_buf_s *buf)
} }
} }
wlinfo("opcode %x len %u\n", opcode, buf->len); wlinfo("opcode %04x len %u\n", opcode, buf->len);
/* Host Number of Completed Packets can ignore the ncmd value and does not /* Host Number of Completed Packets can ignore the ncmd value and does not
* generate any cmd complete/status events. * generate any cmd complete/status events.
@ -1502,7 +1503,7 @@ int bt_hci_cmd_send_sync(uint16_t opcode, FAR struct bt_buf_s *buf,
} }
} }
wlinfo("opcode %x len %u\n", opcode, buf->len); wlinfo("opcode %04x len %u\n", opcode, buf->len);
/* Set up for the wait */ /* Set up for the wait */
@ -1587,7 +1588,7 @@ int bt_hci_cmd_send_sync(uint16_t opcode, FAR struct bt_buf_s *buf,
{ {
*rsp = buf->u.hci.sync; *rsp = buf->u.hci.sync;
} }
else if (buf->u.hci.sync) else if (buf->u.hci.sync != NULL)
{ {
bt_buf_release(buf->u.hci.sync); bt_buf_release(buf->u.hci.sync);
} }