Skip to content

Commit e027f06

Browse files
cvinayakcarlescufi
authored andcommitted
Bluetooth: Controller: Fix missing recv fifo reset
Fix missing recv fifo reset on HCI reset. This fix handles a scenario where in Rx Prio thread has enqueued a node rx, Tx thread handles HCI Reset Command, and Rx thread wakes up from call to k_fifo_get to handle invalid node rx. The changes here ensure Rx thread does not get any invalid node rx post HCI Reset Command handled in Tx thread. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent 1eb9d36 commit e027f06

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

subsys/bluetooth/controller/hci/hci.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ static void reset(struct net_buf *buf, struct net_buf **evt)
455455
k_poll_signal_raise(hbuf_signal, 0x0);
456456
}
457457
#endif
458+
459+
hci_recv_fifo_reset();
458460
}
459461

460462
#if defined(CONFIG_BT_HCI_ACL_FLOW_CONTROL)

subsys/bluetooth/controller/hci/hci_driver.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,21 @@ isoal_status_t sink_sdu_write_hci(void *dbuf,
206206
}
207207
#endif
208208

209+
void hci_recv_fifo_reset(void)
210+
{
211+
/* NOTE: As there is no equivalent API to wake up a waiting thread and
212+
* reinitialize the queue so it is empty, we use the cancel wait and
213+
* initialize the queue. As the Tx thread and Rx thread are co-operative
214+
* we should be relatively safe doing the below.
215+
* Added k_sched_lock and k_sched_unlock, as native_posix seems to
216+
* swap to waiting thread on call to k_fifo_cancel_wait!.
217+
*/
218+
k_sched_lock();
219+
k_fifo_cancel_wait(&recv_fifo);
220+
k_fifo_init(&recv_fifo);
221+
k_sched_unlock();
222+
}
223+
209224
static struct net_buf *process_prio_evt(struct node_rx_pdu *node_rx,
210225
uint8_t *evt_flags)
211226
{
@@ -591,7 +606,7 @@ static void recv_thread(void *p1, void *p2, void *p3)
591606
int err;
592607

593608
err = k_poll(events, 2, K_FOREVER);
594-
LL_ASSERT(err == 0);
609+
LL_ASSERT(err == 0 || err == -EINTR);
595610
if (events[0].state == K_POLL_STATE_SIGNALED) {
596611
events[0].signal->signaled = 0U;
597612
} else if (events[1].state ==

subsys/bluetooth/controller/hci/hci_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extern atomic_t hci_state_mask;
3232

3333

3434
void hci_init(struct k_poll_signal *signal_host_buf);
35+
void hci_recv_fifo_reset(void);
3536
struct net_buf *hci_cmd_handle(struct net_buf *cmd, void **node_rx);
3637
void hci_evt_encode(struct node_rx_pdu *node_rx, struct net_buf *buf);
3738
uint8_t hci_get_class(struct node_rx_pdu *node_rx);

0 commit comments

Comments
 (0)