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

Re-connect to peripheral device fails on IDF v4.4.7 #64

Closed andreaslundeen closed 3 months ago

andreaslundeen commented 4 months ago

Works in 4.4.6. But the updates in https://github.com/espressif/esp-nimble/commit/c50690e1b7794b9485921b1991b86387141832c0 breaks this and I am unable to re-connect. Seems that the added lines in ble_gap_connect() should be guarded with :

if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY)

if (ble_host_rpa_enabled())
{
struct ble_hs_resolv_entry *rl = NULL;
rl = ble_hs_resolv_list_find(bhc_peer_addr.val);

if (rl != NULL) {
    BLE_HS_LOG(INFO, "%08x", *(uint32_t*)rl->rl_peer_rpa);
    memcpy(bhc_peer_addr.val, rl->rl_peer_rpa, BLE_DEV_ADDR_LEN);
    bhc_peer_addr.type = rl->rl_addr_type;
}
}

endif

Running on an ESP32 device where MYNEWT_VAL(BLE_HOST_BASED_PRIVACY) is defaulted to 1 in configuration.

rahult-github commented 4 months ago

Hi @andreaslundeen , Thanks for reporting, we will fix this asap.

darshan7patel commented 4 months ago

Hi @andreaslundeen , Kindly use the attahced patch. Please let me know if any addtional information is required. reconnect_failure.txt

andreaslundeen commented 4 months ago

Hi @andreaslundeen , Kindly use the attahced patch. Please let me know if any addtional information is required. reconnect_failure.txt

error: patch failed: nimble/host/src/ble_gap.c:5808 error: nimble/host/src/ble_gap.c: patch does not apply

Please note that this is based on ESP IDF 4.4.7

darshan7patel commented 4 months ago

Please kindle check the below: reconnect_patch.txt

andreaslundeen commented 4 months ago

Please kindle check the below: reconnect_patch.txt

Sorry, still errors. (# RELEASE NOTES

18 March 2020 - Apache NimBLE v1.3.0 ...)

git apply -v --check reconnect_patch.txt Checking patch nimble/host/src/ble_gap.c... error: while searching for: memcpy(bhc_peer_addr.val, peer_addr->val, BLE_DEV_ADDR_LEN);

if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY)

struct ble_hs_resolv_entry *rl = NULL;
rl = ble_hs_resolv_list_find(bhc_peer_addr.val);

if (rl != NULL && rl->rl_isrpa) {
    memcpy(bhc_peer_addr.val, rl->rl_peer_rpa, BLE_DEV_ADDR_LEN);
    bhc_peer_addr.type = rl->rl_addr_type;
}

endif

error: patch failed: nimble/host/src/ble_gap.c:5372 error: nimble/host/src/ble_gap.c: patch does not apply

rahult-github commented 4 months ago

Hi @andreaslundeen , please try this patch. I think, the previous patch was generated from tip of the tree which results in the failure at your end. This should now work. reconnect_patch_v2.txt

andreaslundeen commented 4 months ago

Hi @andreaslundeen , please try this patch. I think, the previous patch was generated from tip of the tree which results in the failure at your end. This should now work. reconnect_patch_v2.txt

With this latest patch file (including my suggested guard) it works.

andreaslundeen commented 4 months ago

When will the fix part of an 4.4 bugfix release?

rahult-github commented 4 months ago

Hi @andreaslundeen ,

Yes, the change has been merged internally and backported to release branches too. You should see it on github soon once github syncs .

rahult-github commented 3 months ago

Change is available on github . Closing issue.