Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLE ANCS Pairing Failure on ESP32 Using BLEDevice Library – Error 0x66 and Bond Loss on Repeated Connect/Disconnect #1201

Open
nitin-jethava opened this issue Dec 16, 2024 · 0 comments

Comments

@nitin-jethava
Copy link

I’m currently working on an ESP32 project using the BLEDevice library in the Arduino environment (PlatformIO). I encountered an issue where BLE pairing frequently fails after repeated connection and disconnection cycles, resulting in an error code 0x66.

This behavior seems similar to an issue previously addressed in ESP-IDF, where the bonding information was being cleared during certain failure scenarios, but the smartphone retained its bond information. In ESP-IDF, this issue was resolved by modifying the bond retention logic under specific error conditions. The fix worked effectively in ESP-IDF (Reference: [ESP-IDF GitHub Issue #14977]

The solution involved ensuring that bond information is not cleared when the failure reason is 0x66 (SMP timeout). In ESP-IDF, the following change was applied to prevent bond clearing for 0x66 errors:

if (sec_event.auth_cmpl.fail_reason != BTA_DM_AUTH_SMP_CONN_TOUT) {
    bta_dm_remove_sec_dev_entry(bda);
}

This was modified to:

if (sec_event.auth_cmpl.fail_reason != BTA_DM_AUTH_SMP_CONN_TOUT) {
    // bta_dm_remove_sec_dev_entry(bda);
}

Now, I’d like to apply a similar solution in the BLEDevice library to resolve the problem in the Arduino environment.


Observations:

I added debug logs to monitor the behavior, and here are the key findings:

  1. Before Connection:

    • The bond list size was logged after advertising started:
      I (48502) BLE_ANCS: advertising start success  
      I (48502) BONDING_LIST: Bond list size after restart advertises: 3  
      
  2. After Connection:

    • Successful pairing was observed, with bond information intact:
      I (50842) BLE_ANCS: ESP_GATTC_CONNECT_EVT  
      I (50842) BONDING_LIST: Bond list size after connection: 3  
      I (47092) BLE_ANCS: pair status = success  
      
  3. After Disconnection:

    • Bond information was lost after specific disconnection errors:
      I (51832) BLE ANCS: pair status = fail  
      I (51832) BLE ANCS: fail reason = 0x66  
      I (51842) BONDING_LIST: Bond list size after disconnection: 2  
      
  4. Reconnection Attempts:

    • Subsequent attempts failed, with persistent bond inconsistencies:
      I (52902) BLE ANCS: fail reason = 0x66  
      I (52912) BONDING_LIST: Bond list size after disconnection: 2  
      

It appears the BLEDevice library does not handle bond retention as effectively as the ESP-IDF implementation.


Questions:

  1. How should this issue be addressed in the BLEDevice library?
  2. Could you guide me on how to modify the bond retention logic to align with the ESP-IDF fix?

Offer to Assist:

If there’s anything else I can provide—such as additional logs, specific test cases, or further debugging details—please don’t hesitate to let me know. I’m happy to assist in any way to help address this issue.

Thank you for your time and support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant