Skip to content

fix(nrf52): add BLE security timeout and advertising watchdog#39

Open
ipduffy wants to merge 2 commits intoweebl2000:nrf52-watchdog-brownoutfrom
ipduffy:fix/nrf52-ble-stack-hang
Open

fix(nrf52): add BLE security timeout and advertising watchdog#39
ipduffy wants to merge 2 commits intoweebl2000:nrf52-watchdog-brownoutfrom
ipduffy:fix/nrf52-ble-stack-hang

Conversation

@ipduffy
Copy link

@ipduffy ipduffy commented Mar 19, 2026

Commit meshcore-dev@25ea953 introduced a condition where a BLE connection that is established but not yet encrypted could result in a hung BLE stack under certain conditions.

If onConnect is called with a valid connection_handle, the _isDeviceConnected flag remains set to false. This prevents the watchdog loop on lines 336-346 from running until after the onSecured function is called and the _isDeviceConnected flag is set to true.

For various reasons that are apparently more common in iPhones versus Android devices, the establishment of encryption is more likely to not complete, which would leave the nRF device BLE stack in a hung state.

To address this potential for a hung state I've implemented a timeout (BLE_SECURITY_TIMEOUT_MS) on the call to onSecured of 15 seconds, so that if a BLE connection is established via onConnect without the subsequent call to onSecured within that time, then disconnect is called, allowing the device to return to an advertising state and allow further connection attempts.

I have tested this patched firmware on a RAK 4631 board and it's been stable without any BLE issues for the past 24 hours.

@weebl2000 weebl2000 force-pushed the nrf52-watchdog-brownout branch from f20e5af to 3473b6a Compare March 23, 2026 13:26
@ipduffy
Copy link
Author

ipduffy commented Mar 23, 2026

I made some changes to the code at the request of @robekl on the main repository and pushed them today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant