espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.33k stars 7.2k forks source link

BLE gattc service cache information is not deleted whent the configured BLE namespace is deleted (IDFGH-12910) #13870

Open sergiutigu opened 3 months ago

sergiutigu commented 3 months ago

Answers checklist.

IDF version.

v4.3

Espressif SoC revision.

ESP32

Operating System used.

Windows

How did you build your project?

VS Code IDE

If you are using Windows, please specify command line type.

None

Development Kit.

custom board

Power Supply used.

USB

What is the expected behavior?

when the configured namespace that stores the bonding information for a particular device is deleted , the cached service information to be also deleted.

What is the actual behavior?

when the configured namespace that stores the bonding information for a particular device is deleted , the cached service information is not deleted. and there is no way of deleting that, except deleting the entire partition, which we can't do since we have data than we don't want to loose.

Steps to reproduce.

  1. In the menuconfig enable CONFIG_BT_GATTC_CACHE_NVS_FLASH.
  2. Start BLE as a central.
  3. Set the namespace name that keeps the bonding information: ErrorCode_s32 = esp_ble_config_file_path_update((char_t*)Filename_pac); if (ErrorCode_s32 != ESP_OK) { }
  4. Bond a peripheral
  5. discover the services. This should save them into flash.
  6. Disconnect.
  7. delete the Filename_pac. This deletes the bonding information only.
  8. Start the BLE again as central.
  9. Bond again the peripheral.
  10. Services are still stored inside nvs. ...

Debug Logs.

No response

More Information.

No response

esp-zhp commented 3 months ago

If you need to delete the service information within the NVS, you can use the API esp_ble_gattc_cache_clean.

exilat commented 3 months ago

The issue here is that can only be applied if you BLE stack is running. But the need to deleted the nvs namespace is coming from the need to perform a factory setting of the device. This must be implemented regardless of the state of the BLE stack. What i am saying that there is a missing functioanlity in the BLE stack, and that is blocking us to implement factory settings, Till now we could avoid it but not on the new platform.

sergiutigu commented 1 month ago

is there any input that is expected from my side on this matter?

Weijian-Espressif commented 1 month ago
  1. esp_ble_config_file_path_update is not allowed to be called while the Bluetooth stack is running, and can only be used before bluedroid init, which is now supported by IDF v5.2 and above. esp_err_t esp_bt_config_file_path_update(const char *file_path);
  2. If you need to delete the service information within the NVS, you can use the API esp_ble_gattc_cache_clean.
esp-zhp commented 1 month ago

@sergiutigu "The issue is that this can only be applied if your BLE stack is running. You are correct.

Could you describe your use case? Why do you need to use this related API when the BLE stack is not running?"

sergiutigu commented 1 month ago

we need to perform a factory settings. This can happen while the BT are running or not. Also we have 2 version of factory settings: BT Factory Settings/Wifi Factory Settings. So we need to be able to clear "all BT specific only" nvs files, whiteout affecting the Wifi information stored in flash while BT service are off. Factory settings performs a reset, and we do not have time to start the BT stack before the reset comes. We only have time to delete files, namespace from nvs space.

esp-zhp commented 1 month ago

.Based on the Bluedroid host architecture, the GATTC cache can only be cleared after Bluedroid has been initialized. We do not currently support this method. Please consider alternative approaches.clear the corresponding GATTC cache after initialization.