Repeated bonding with NimBLE
Posted: 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:
But, after doing some temporary adjustments inside the ble_gap.c file, the bonding seems to be saved in flash, as shown below:
I have also noticed that the ESP32 and the phone have different address types, could this be one of the problems?
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
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:
- 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
- error persisting our sec; too many entries (3)
- looking up our sec;
- looking up our sec;
- 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
- 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:
- 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
- D (698332) nvs: nvs_open_from_partition nimble_bond 1
- D (698333) nvs: nvs_get_str_or_blob our_sec_1
- D (698345) nvs: nvs_get_str_or_blob our_sec_1
- D (698347) nvs: nvs_close 179
- D (698348) nvs: nvs_open_from_partition nimble_bond 1
- D (698359) nvs: nvs_get_str_or_blob our_sec_2
- D (698360) nvs: nvs_close 180
- D (698361) nvs: nvs_open_from_partition nimble_bond 1
- D (698372) nvs: nvs_get_str_or_blob our_sec_3
- D (698373) nvs: nvs_close 181
- D (698374) NIMBLE_NVS: Persisting our sec value to NVS...
- D (698385) nvs: nvs_open_from_partition nimble_bond 1
- D (698386) nvs: nvs_get_str_or_blob our_sec_1
- D (698388) nvs: nvs_get_str_or_blob our_sec_1
- D (698400) nvs: nvs_close 182
- D (698401) nvs: nvs_open_from_partition nimble_bond 1
- D (698402) nvs: nvs_get_str_or_blob our_sec_2
- D (698403) nvs: nvs_close 183
- D (698413) NIMBLE_NVS: Empty NVS index found = 2 for obj_type = 1
- D (698415) nvs: nvs_open_from_partition nimble_bond 1
- D (698416) nvs: nvs_set_blob our_sec_2 80
- D (698430) nvs: nvs_close 184
- 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
- D (698456) nvs: nvs_open_from_partition nimble_bond 1
- D (698458) nvs: nvs_get_str_or_blob peer_sec_1
- D (698459) nvs: nvs_get_str_or_blob peer_sec_1
- D (698471) nvs: nvs_close 185
- D (698472) nvs: nvs_open_from_partition nimble_bond 1
- D (698473) nvs: nvs_get_str_or_blob peer_sec_2
- D (698474) nvs: nvs_close 186
- D (698485) nvs: nvs_open_from_partition nimble_bond 1
- D (698486) nvs: nvs_get_str_or_blob peer_sec_3
- D (698487) nvs: nvs_close 187
- D (698498) NIMBLE_NVS: Persisting peer sec value in NVS...
- D (698499) nvs: nvs_open_from_partition nimble_bond 1
- D (698500) nvs: nvs_get_str_or_blob peer_sec_1
- D (698512) nvs: nvs_get_str_or_blob peer_sec_1
- D (698514) nvs: nvs_close 188
- D (698515) nvs: nvs_open_from_partition nimble_bond 1
- D (698526) nvs: nvs_get_str_or_blob peer_sec_2
- D (698527) nvs: nvs_close 189
- D (698528) NIMBLE_NVS: Empty NVS index found = 2 for obj_type = 2
- D (698539) nvs: nvs_open_from_partition nimble_bond 1
- D (698540) nvs: nvs_set_blob peer_sec_2 80
- D (698544) nvs: nvs_close 190
- 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
- host tx hci data; handle=0 length=9
- ble_hs_hci_acl_tx(): 0x00 0x00 0x09 0x00 0x05 0x00 0x04 0x00 0x07 0x06 0x00 0x09 0x00
- 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?
- I (263760) BT: encryption change event; status=0
- I (263762) BT: handle=0 our_ota_addr_type=0 our_ota_addr=b8:f0:09:8f:9b:be
- I (263764) BT: our_id_addr_type=0 our_id_addr=b8:f0:09:8f:9b:be
- I (263775) BT: peer_ota_addr_type=1 peer_ota_addr=75:32:8e:3d:90:1b
- I (263776) BT: peer_id_addr_type=1 peer_id_addr=75:32:8e:3d:90:1b
- 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