Repeated bonding with NimBLE

flonas
Posts: 3
Joined: Mon Aug 16, 2021 6:11 am

Repeated bonding with NimBLE

Postby flonas » Mon Aug 16, 2021 8:41 am

Hello,

I am currently developing an app for ESP32 using NimBLE, that will pair and bond with an Android application, using "just works" method. I use the nRF Connect app from Play Store to connect.

The problem I am facing is that, sometimes, even if the devices are bonded, the bonding is repeated. I cannot tell exactly when the bonding will be repeated, it seems random to me. I checked the peer address and I can confirm that the bonding is repeated even if the address did not change.

At the beginning, I was getting the following error:

  1. persisting our sec; ediv=0 rand=0 authenticated=0 ltk=0x4f 0xdc 0x86 0x02 0x82 0x74 0xa3 0xd3 0x02 0x7a 0x56 0xcd 0x7c 0x37 0x7d 0x62
  2. error persisting our sec; too many entries (3)
  3. looking up our sec;
  4. looking up our sec;
  5. persisting peer sec; ediv=0 rand=0 authenticated=0 ltk=0x4f 0xdc 0x86 0x02 0x82 0x74 0xa3 0xd3 0x02 0x7a 0x56 0xcd 0x7c 0x37 0x7d 0x62
  6. error persisting peer sec; too many entries (3)

But, after doing some temporary adjustments inside the ble_gap.c file, the bonding seems to be saved in flash, as shown below:

  1. persisting our sec; ediv=0 rand=0 authenticated=0 ltk=0x0f 0x5c 0x56 0xc7 0x21 0x62 0x09 0x1c 0x31 0x31 0x80 0x29 0x47 0xc2 0x4f 0x44
  2. D (698332) nvs: nvs_open_from_partition nimble_bond 1
  3. D (698333) nvs: nvs_get_str_or_blob our_sec_1
  4. D (698345) nvs: nvs_get_str_or_blob our_sec_1
  5. D (698347) nvs: nvs_close 179
  6. D (698348) nvs: nvs_open_from_partition nimble_bond 1
  7. D (698359) nvs: nvs_get_str_or_blob our_sec_2
  8. D (698360) nvs: nvs_close 180
  9. D (698361) nvs: nvs_open_from_partition nimble_bond 1
  10. D (698372) nvs: nvs_get_str_or_blob our_sec_3
  11. D (698373) nvs: nvs_close 181
  12. D (698374) NIMBLE_NVS: Persisting our sec value to NVS...
  13. D (698385) nvs: nvs_open_from_partition nimble_bond 1
  14. D (698386) nvs: nvs_get_str_or_blob our_sec_1
  15. D (698388) nvs: nvs_get_str_or_blob our_sec_1
  16. D (698400) nvs: nvs_close 182
  17. D (698401) nvs: nvs_open_from_partition nimble_bond 1
  18. D (698402) nvs: nvs_get_str_or_blob our_sec_2
  19. D (698403) nvs: nvs_close 183
  20. D (698413) NIMBLE_NVS: Empty NVS index found = 2 for obj_type = 1
  21. D (698415) nvs: nvs_open_from_partition nimble_bond 1
  22. D (698416) nvs: nvs_set_blob our_sec_2 80
  23. D (698430) nvs: nvs_close 184
  24.  
  25. persisting peer sec; ediv=0 rand=0 authenticated=0 ltk=0x0f 0x5c 0x56 0xc7 0x21 0x62 0x09 0x1c 0x31 0x31 0x80 0x29 0x47 0xc2 0x4f 0x44
  26. D (698456) nvs: nvs_open_from_partition nimble_bond 1
  27. D (698458) nvs: nvs_get_str_or_blob peer_sec_1
  28. D (698459) nvs: nvs_get_str_or_blob peer_sec_1
  29. D (698471) nvs: nvs_close 185
  30. D (698472) nvs: nvs_open_from_partition nimble_bond 1
  31. D (698473) nvs: nvs_get_str_or_blob peer_sec_2
  32. D (698474) nvs: nvs_close 186
  33. D (698485) nvs: nvs_open_from_partition nimble_bond 1
  34. D (698486) nvs: nvs_get_str_or_blob peer_sec_3
  35. D (698487) nvs: nvs_close 187
  36. D (698498) NIMBLE_NVS: Persisting peer sec value in NVS...
  37. D (698499) nvs: nvs_open_from_partition nimble_bond 1
  38. D (698500) nvs: nvs_get_str_or_blob peer_sec_1
  39. D (698512) nvs: nvs_get_str_or_blob peer_sec_1
  40. D (698514) nvs: nvs_close 188
  41. D (698515) nvs: nvs_open_from_partition nimble_bond 1
  42. D (698526) nvs: nvs_get_str_or_blob peer_sec_2
  43. D (698527) nvs: nvs_close 189
  44. D (698528) NIMBLE_NVS: Empty NVS index found = 2 for obj_type = 2
  45. D (698539) nvs: nvs_open_from_partition nimble_bond 1
  46. D (698540) nvs: nvs_set_blob peer_sec_2 80
  47. D (698544) nvs: nvs_close 190
  48.  
  49. ble_hs_hci_evt_acl_process(): conn_handle=0 pb=2 len=13 data=0x09 0x00 0x04 0x00 0x06 0x01 0x00 0xff 0xff 0x00 0x28 0x01 0x18
  50. host tx hci data; handle=0 length=9
  51. ble_hs_hci_acl_tx(): 0x00 0x00 0x09 0x00 0x05 0x00 0x04 0x00 0x07 0x06 0x00 0x09 0x00
  52. ble_hs_hci_evt_acl_process(): conn_handle=0 pb=2 len=7 data=0x03 0x00 0x04 0x00 0x0a 0x1f 0x00

I have also noticed that the ESP32 and the phone have different address types, could this be one of the problems?

  1. I (263760) BT: encryption change event; status=0
  2. I (263762) BT: handle=0 our_ota_addr_type=0 our_ota_addr=b8:f0:09:8f:9b:be
  3. I (263764) BT: our_id_addr_type=0 our_id_addr=b8:f0:09:8f:9b:be
  4. I (263775) BT: peer_ota_addr_type=1 peer_ota_addr=75:32:8e:3d:90:1b
  5. I (263776) BT: peer_id_addr_type=1 peer_id_addr=75:32:8e:3d:90:1b
  6. I (263788) BT: conn_itvl=36 conn_latency=0 supervision_timeout=500 encrypted=1 authenticated=0 bonded=1

I have read and tried the solutions presented here https://www.esp32.com/viewtopic.php?t=13049 and https://www.esp32.com/viewtopic.php?t=14966, but I did not have any success. Probably I am doing something wrong, I do not have much experience with BLE.

Please let me know if you need any additional information.

Any suggestion would be greatly appreciated.

Florin

Who is online

Users browsing this forum: No registered users and 162 guests