From d007e11cbd9fb2064452a1fb654285ad8a0ba07c Mon Sep 17 00:00:00 2001 From: Andrzej Kaczmarek Date: Fri, 30 Aug 2024 16:27:06 +0200 Subject: [PATCH] nimble/transport: Fix race in nrf5340 IPC transport The HCI transport is initialized after LL task is initialized, but the IPC itself is initialized before LL task. If host on appcore starts before HCI transport is initialized on netcore, it can put HCI Reset in IPC shm before we can receive it and handle. This causes host to send 2nd HCI Reset which triggers handling of data in IPC shm and will fail because we cannot handle 2 HCI commands at the same time (i.e. 2x HCI Reset). This fixes the problem by triggering read from IPC shm just after HCI transport is initialized so we can handle command that was sent there before we were ready to receive it. --- nimble/transport/nrf5340/src/nrf5340_ble_hci.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nimble/transport/nrf5340/src/nrf5340_ble_hci.c b/nimble/transport/nrf5340/src/nrf5340_ble_hci.c index 5da5398a0..679cfb124 100644 --- a/nimble/transport/nrf5340/src/nrf5340_ble_hci.c +++ b/nimble/transport/nrf5340/src/nrf5340_ble_hci.c @@ -121,12 +121,18 @@ nrf5340_ble_hci_trans_rx(int channel, void *user_data) static void nrf5340_ble_hci_init(void) { + os_sr_t sr; + SYSINIT_ASSERT_ACTIVE(); #if MYNEWT_VAL(BLE_TRANSPORT_RX_TASK) ble_transport_rx_register(rx_func, NULL); #endif ipc_nrf5340_recv(IPC_RX_CHANNEL, nrf5340_ble_hci_trans_rx, NULL); + + OS_ENTER_CRITICAL(sr); + nrf5340_ble_hci_trans_rx(IPC_RX_CHANNEL, NULL); + OS_EXIT_CRITICAL(sr); } #if MYNEWT_VAL(BLE_CONTROLLER)