apache / apache/mynewt-nimble

Nimble stack resets with reason 0x13

Open
#993 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
893
Forks
512
Avg merge
13d 31m
Merged PRs (30d)
7

Description

Hello all,

I'm implementing the nimble Bluetooth stack (esp-idf v4.1.1) into my ESP32-WROOM-32D project which has been set as BLE peripheral. When I walk away with my Phone or disable bluetooth, and then come back in range or enable bleutooth and try to connect again, the nimble reset_cb is called with error 0x13 (BLE_HS_ETIMEOUT_HCI).

I've got two devices which are currently bonded, 1 still connected, on the other I execute the steps as described above. The problem is that I cannot always reproduce the issue, my guess is that this is due to Bluetooth addresses changing is not always at the same moment?

My bluetooth device has been set up as followed:
```C++
void CEspNimbleBluetoothDevice::Init()
{
esp_err_t result;
result = esp_nimble_hci_and_controller_init();
Assert(result == ESP_OK);

nimble_port_init();

ble_hs_cfg.reset_cb = PeripheralOnResetCallback;
ble_hs_cfg.sync_cb = PeripheralOnSyncCallback;
ble_hs_cfg.gatts_register_cb = GattRegisterEventCallback;
ble_hs_cfg.gatts_register_arg = reinterpret_cast(this);
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;

ble_hs_cfg.sm_io_cap = BLE_SM_IO_CAP_NO_IO; // No input/output capabilities (just works)
ble_hs_cfg.sm_bonding = 1; // Enable bonding
ble_hs_cfg.sm_sc = 1; // Use secure connection
ble_hs_cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID; // Enable LTK + IRK
ble_hs_cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID; // Enable LTK + IRK

ble_svc_gap_init();
ble_svc_gatt_init();

memset(m_serviceTable, 0, sizeof(m_serviceTable));
memset(m_characteristicRegistrationTable, 0, sizeof(m_characteristicRegistrationTable));
}
```
See SDK config for more information: [sdkconfig.txt](https://github.com/espressif/esp-nimble/files/6632082/sdkconfig.txt)

The image below contains my debug log:
![image](https://user-images.githubusercontent.com/83207230/121542286-52a49900-ca08-11eb-90e0-a9da2fa34375.png)

The following things in my log stand out:
- Unhandled event 0x10 - BLE_GAP_EVENT_ENC_CHANGE
- Unhandled event 0x15 - BLE_GAP_EVENT_MTU

_Looking at the bleprph example both events are not required to be handled but will be returned with 0 directly._

- The reset_cb is called, with error: 0x13 - BLE_HS_ETIMEOUT_HCI
- Advertising start error: 0x15 - BLE_HS_ENOADDR, probably because the nimble stack just reset, see error 0x13

Hopefully somebody can help me with this.

Equal to issue [#27](https://github.com/espressif/esp-nimble/issues/27).

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the ESP-IDF Nimble initialization shown in the issue, sdkconfig.txt, and the bleprph example's handling of BLE_GAP_EVENT_ENC_CHANGE and BLE_GAP_EVENT_MTU. Trace reset_cb and the subsequent advertising-start failure, then establish a reproducible bonded-device reconnect case and document the cause of BLE_HS_ETIMEOUT_HCI.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.