Skip to content

Timeout connecting from public central address to RPA peripheral address. #356

@gkoh

Description

@gkoh

esp-nimble-cpp: 2.3.1
esp-idf: 5.4.2

I'm on an ESP32 SoC (just ESP32, no C, no H, no S).
If I do the following:

NimBLEDevice::setSecurityAuth(true, true, true);

// claim YESNO to enable numeric LE security
NimBLEDevice::setSecurityIOCap(BLE_HS_IO_DISPLAY_YESNO);

NimBLEDevice::setSecurityInitKey(BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID);
NimBLEDevice::setSecurityRespKey(BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID);
NimBLEDevice::setOwnAddrType(BLE_OWN_ADDR_PUBLIC);

and connect the esp32 as a central to an nRF Connect peripheral on Android:

  • initial pairing and bonding works
  • subsequent re-connect timeouts

I eventually tracked it down to the automagic peer address resolution which is occurring here on advertisements:
https://github.com/espressif/esp-nimble/blob/48ca84312ea388fcfdb9cb9c85a8a8d4f9283302/nimble/host/src/ble_hs_hci_evt.c#L734

My knowledge is shallow, but I believe the timeout is occurring because esp-nimble has auto-resolved the advertisement address, when we need the 'actual' address to form a connection.
If I comment out the above peer address resolution in the advertisement handling, everything works as expected.
This appears related to an old esp-nimble issue:
espressif/esp-nimble#10

As the code is conditional on MYNEWT_VAL(BLE_HOST_BASED_PRIVACY), and I don't need host RPA, I disabled it in menuconfig (CONFIG_BT_NIMBLE_HOST_BASED_PRIVACY).
Much to my surprise, this had zero effect on esp32 because of this:
https://github.com/espressif/esp-idf/blob/47a659cd3ee5f73a253d2a7af02781a73a44356d/components/bt/host/nimble/port/include/esp_nimble_cfg.h#L953

Whilst this is not a problem in esp-nimble-cpp there appears to have been numerous issues on RPA handling in the past and I seek advice on how to proceed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions