espressif / esp-nimble

A fork of NimBLE stack, for use with ESP32 and ESP-IDF
Apache License 2.0
76 stars 49 forks source link

Nimble stack resets with reason 0x13 #27

Open Teu97 opened 3 years ago

Teu97 commented 3 years ago

Hello again,

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:

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<void*>(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

The image below contains my debug log: image

The following things in my log stand out:

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

Hopefully somebody can help me with this.

Teu97 commented 2 years ago

Hi all, I'm still having trouble with this issue. Can anyone help?