Skip to content

Commit

Permalink
Bluetooth: host: hci: handle error case
Browse files Browse the repository at this point in the history
bt_hci_cmd_send_sync will return 0 on error if
CONFIG_BT_ASSERT is disabled, which make bt_enable
success even if there is no response from controller

Signed-off-by: Karthikeyan Krishnasamy <karthikeyan@linumiz.com>
  • Loading branch information
karthi012 committed Dec 29, 2023
1 parent 605435c commit cf6c3b5
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions subsys/bluetooth/host/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ int bt_hci_cmd_send_sync(uint16_t opcode, struct net_buf *buf,

err = k_sem_take(&sync_sem, HCI_CMD_TIMEOUT);
BT_ASSERT_MSG(err == 0, "command opcode 0x%04x timeout with err %d", opcode, err);
if (err) {
net_buf_unref(buf);
return err;
}

status = cmd(buf)->status;
if (status) {
Expand Down Expand Up @@ -3940,6 +3944,17 @@ static void init_work(struct k_work *work)
int err;

err = bt_init();
if (err) {
bt_dev.drv->close();

#if defined(CONFIG_BT_RECV_WORKQ_BT)
/* Abort RX thread */
k_thread_abort(&bt_workq.thread);
#endif

k_thread_abort(&tx_thread_data);
}

if (ready_cb) {
ready_cb(err);
}
Expand Down Expand Up @@ -4065,17 +4080,31 @@ int bt_enable(bt_ready_cb_t cb)
err = bt_dev.drv->open();
if (err) {
LOG_ERR("HCI driver open failed (%d)", err);
return err;
goto error;
}

bt_monitor_send(BT_MONITOR_OPEN_INDEX, NULL, 0);

if (!cb) {
return bt_init();
if (cb) {
k_work_submit(&bt_dev.init);
} else {
err = bt_init();
if (err) {
bt_dev.drv->close();
goto error;
}
}

k_work_submit(&bt_dev.init);
return 0;

error:
#if defined(CONFIG_BT_RECV_WORKQ_BT)
/* Abort RX thread */
k_thread_abort(&bt_workq.thread);
#endif

k_thread_abort(&tx_thread_data);
return err;
}

int bt_disable(void)
Expand Down

0 comments on commit cf6c3b5

Please sign in to comment.