Do I need to clear bonded devices?

a-soft-dev
Posts: 3
Joined: Fri Jul 13, 2018 7:31 am

Do I need to clear bonded devices?

Postby a-soft-dev » Fri Jul 13, 2018 7:40 am

Hi,

When using ble with encryption a bond is made and the long term keys are stored in NVS.

First question: How many bonds can be stored?

Seconds question: What happens when we reach that limit, does it delete the oldest bond to make room for the new one or do I need to clear the bonds with the "esp_ble_remove_bond_device" command?

In the example below it looks like you never need to call the remove bond function. But I can't find anything else about it.
https://github.com/espressif/esp-idf/bl ... emo.c#L537

Thank you.

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

Re: Do I need to clear bonded devices?

Postby chegewara » Mon Jul 16, 2018 5:12 pm

I cant answer with 100% accuracy and provide source but if i remember esp32 can store about 12 bonded devices (or whitelisted devices).

esp-idf examples dont implement each single command from API to show how to use it, but as you suspect the oldest bonded device keys should be erased to store new one (not tested myself).

a-soft-dev
Posts: 3
Joined: Fri Jul 13, 2018 7:31 am

Re: Do I need to clear bonded devices?

Postby a-soft-dev » Tue Jul 17, 2018 10:29 am

Ok, thank you.

DanCurram
Posts: 15
Joined: Tue Jun 12, 2018 2:13 pm

Re: Do I need to clear bonded devices?

Postby DanCurram » Thu Nov 22, 2018 3:23 pm

Folks anyone have any pointers on an issue to do with removing bonded devices


I use the esp_bt_gap_remove_bond_device call and it returns ESP_OK for each esp_bd_addr_t

but if I reset the device the bonds are still there

The bonds can be removed If I do the above and then try connect a previous bt device and fail it

So if the "Save gattc cache datato nvs flash" is ticked do I have to deinit the Bt module then reinitialise it to delete the bond
settings in nvs ?


Or have I missed something ?

chegewara
Posts: 2375
Joined: Wed Jun 14, 2017 9:00 pm

Re: Do I need to clear bonded devices?

Postby chegewara » Fri Nov 23, 2018 4:17 pm

It suppose to be fixed already, but if you still have this issue then it is not:
https://github.com/espressif/esp-idf/is ... -434152212

DanCurram
Posts: 15
Joined: Tue Jun 12, 2018 2:13 pm

Re: Do I need to clear bonded devices?

Postby DanCurram » Mon Nov 26, 2018 4:32 pm

Thanks for your response

To help put this more in context of how I am using the commands.

I have written code in C to make the esp32 behave similar to a Bluegiga wt12 modules ASCII commands.
The Esp32 module is run as a classic BT SPP device.
There is a WT12 command eg "SET PAIR *\r\n" that is supposed to clear all pairings. e.g.
so I call

Code: Select all


	/*********************************************************** 
	* Get the numbers of bonded/paired devices to the BT module 
	*  to update the WT12 emulation
	************************************************************/
	wPairedDevices = esp_bt_gap_get_bond_device_num();
	if (wPairedDevices)
	{
		/************************************************************
		* Sanity check so not busting array
		******************************************************************************/	
		if (C_PAIR_MAX_DEVICE < wPairedDevices)
		{
			wPairedDevices = C_PAIR_MAX_DEVICE; 
		}
 	tError =  esp_bt_gap_get_bond_device_list(&wDeviceToGet, &tPairedDeviceBtAddr);
	if (ESP_OK  == tError)
	{
[			for (wDeviceToGet = 0; wDeviceToGet < wPairedDevices; wDeviceToGet++)
			{
				tError = esp_bt_gap_remove_bond_device(tPairedDeviceBtAddr[wDeviceToGet]);
#if C_SHOW_DEBUG_MSGS
				if(ESP_OK == tError)
				{
					ESP_LOGI(BT_TAG, "Paired device %d Removed\r\n", wDeviceToGet);              //__func__
				}
				else  //if(ESP_FAIL == tError)
				{
					ESP_LOGI(BT_TAG, "Paired device %d not accepted by wt12 Emulation \r\n", wDeviceToGet);             //__func__
				}
#endif
 			}	
	}
So far every time I have run the code i get the debug msg
Paired device 1 Removed\r\n
Paired device 2 Removed\r\n
Paired device 3 Removed\r\n
etc

I also then have an ascii reset command that calls esp_restart();
When the Esp32 restarts the ram data array with the wt12 emulation is cleared. When the Esp32 BT module is enabled again and I then call
esp_bt_gap_get_bond_device_list() to see if there are paired devices and if there repopulate the pairing array.


Thanks
Dan

Weijian-Espressif
Posts: 29
Joined: Wed Aug 09, 2017 6:16 am

Re: Do I need to clear bonded devices?

Postby Weijian-Espressif » Tue Nov 27, 2018 1:02 pm

ESP32 can store 15 bonded devices, it will delete the oldest bonded device to make room for the new one when the device reaches the limit.

DanCurram
Posts: 15
Joined: Tue Jun 12, 2018 2:13 pm

Re: Do I need to clear bonded devices?

Postby DanCurram » Wed Nov 28, 2018 5:12 pm

Weijian-Espressif
Thanks for your clarification 15 is far more than I need.

But in my case I deliberately want to delete all bonding's at a time of my choosing.

So is this a clarification that the function esp_bt_gap_remove_bond_device() and NVS data associated with bonding is suffering from "Unintended behaviour" or have I missed a step ?

Dan

Weijian-Espressif
Posts: 29
Joined: Wed Aug 09, 2017 6:16 am

Re: Do I need to clear bonded devices?

Postby Weijian-Espressif » Thu Nov 29, 2018 2:47 am

`esp_bt_gap_remove_bond_device()` is used to remove the classic bluetooth encryption key from flash.
`esp_ble_remove_bond_device()` is used to remove the BLE encryption key from flash.

DanCurram
Posts: 15
Joined: Tue Jun 12, 2018 2:13 pm

Re: Do I need to clear bonded devices?

Postby DanCurram » Wed Feb 27, 2019 3:56 pm

neither of these calls work correctly I have tried both calls

esp_bt_gap_remove_bond_device()` is used to remove the classic bluetooth encryption key from flash.
esp_ble_remove_bond_device()` is used to remove the BLE encryption key from flash.


When the esp32 device is reset the previous pairings are restored.

So is there another way to overcome this problem eg erase all the NVM associated with the Bluetooth functionality ?

Who is online

Users browsing this forum: Majestic-12 [Bot] and 268 guests