From d10d0f0b3939dfd2fe934db0fc9bf0eeddaf4b8e Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Mon, 6 Apr 2020 21:16:25 +0200 Subject: [PATCH] Bluetooth: host: Use bluetooth assert on HCI command send error Use bluetooth assert on HCI command send error since this assertion is always enabled and we should not continue after this has failed. Log command status failure with information in order to make it more visible as the HCI status code is more interesting than the -EIO error code returned by the function. Signed-off-by: Joakim Andersson --- subsys/bluetooth/host/hci_core.c | 40 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index d3bba1f3e5f..35174809dac 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -344,6 +344,7 @@ int bt_hci_cmd_send_sync(u16_t opcode, struct net_buf *buf, struct net_buf **rsp) { struct k_sem sync_sem; + u8_t status; int err; if (!buf) { @@ -364,31 +365,30 @@ int bt_hci_cmd_send_sync(u16_t opcode, struct net_buf *buf, net_buf_put(&bt_dev.cmd_tx_queue, buf); err = k_sem_take(&sync_sem, HCI_CMD_TIMEOUT); - __ASSERT(err == 0, "k_sem_take failed with err %d", err); - - BT_DBG("opcode 0x%04x status 0x%02x", opcode, cmd(buf)->status); - - if (cmd(buf)->status) { - switch (cmd(buf)->status) { - case BT_HCI_ERR_CONN_LIMIT_EXCEEDED: - err = -ECONNREFUSED; - break; - default: - err = -EIO; - break; - } + BT_ASSERT_MSG(err == 0, "k_sem_take failed with err %d", err); + status = cmd(buf)->status; + if (status) { + BT_WARN("opcode 0x%04x status 0x%02x", opcode, status); net_buf_unref(buf); - } else { - err = 0; - if (rsp) { - *rsp = buf; - } else { - net_buf_unref(buf); + + switch (status) { + case BT_HCI_ERR_CONN_LIMIT_EXCEEDED: + return -ECONNREFUSED; + default: + return -EIO; } } - return err; + BT_DBG("rsp %p opcode 0x%04x len %u", buf, opcode, buf->len); + + if (rsp) { + *rsp = buf; + } else { + net_buf_unref(buf); + } + + return 0; } #if defined(CONFIG_BT_OBSERVER) || defined(CONFIG_BT_CONN)