"ble_gap_terminate" Occasionally Returns Unexpected HCI Error
- Dominant language
- C
- Stars
- 893
- Forks
- 512
- Avg merge
- 13d 31m
- Merged PRs (30d)
- 7
Description
With my application (on an ESP32), in some cases I have to call "ble_gap_terminate" from within the event callback of "ble_gap_adv_start", for the event "BLE_GAP_EVENT_CONNECT". The NimBLE documentation suggests that making this kind of call from a callback should work without issue. In some cases this call will return "BLE_HS_ENOTCONN," which is expected e.g. if the connection had immediately failed right after the connection event was raised. However, if I force this code path to run repeatedly, then about 1 out of every 2000 times it runs I instead get the HCI error "BLE_ERR_UNK_CONN_ID". This error probably isn't supposed to leak out like this in normal use.
Looking at the source for "ble_gap_terminate", it appears that the check for "BLE_HS_ENOTCONN" is implemented by a call to "ble_hs_conn_find," which is run before the HCI command is transmitted. There are several concurrency-related reasons why that check might pass, even though the later HCI command will fail. It'd probably be better to specifically check for the "BLE_ERR_UNK_CONN_ID" HCI error, and return "BLE_HS_ENOTCONN" in that case.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing ble_gap_terminate, including its ble_hs_conn_find check and the HCI command path reached from the BLE_GAP_EVENT_CONNECT callback. Reproduce the repeated termination scenario if possible, then verify that BLE_ERR_UNK_CONN_ID is handled as BLE_HS_ENOTCONN without changing other HCI errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot, networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100