mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
ble_mesh: Add an API to directly erase mesh info
This commit is contained in:
parent
f34f7bade6
commit
5c2e8930f9
@ -724,6 +724,19 @@ uint8_t esp_ble_mesh_provisioner_get_free_settings_user_id_count(void)
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE */
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_direct_erase_settings(void)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_PROVISIONER_DIRECT_ERASE_SETTINGS;
|
||||
|
||||
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_start_recv_heartbeat(void)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
@ -614,6 +614,18 @@ uint8_t esp_ble_mesh_provisioner_get_settings_index(const char *user_id);
|
||||
*/
|
||||
uint8_t esp_ble_mesh_provisioner_get_free_settings_user_id_count(void);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to directly erase the stored
|
||||
* mesh information from flash.
|
||||
*
|
||||
* @note This function can be invoked when the mesh stack is not initialized
|
||||
* or has been deinitialized.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_direct_erase_settings(void);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to start receiving and processing
|
||||
* heartbeat messages.
|
||||
|
@ -806,6 +806,7 @@ typedef enum {
|
||||
ESP_BLE_MESH_PROVISIONER_RELEASE_SETTINGS_WITH_USER_ID_COMP_EVT, /*!< Provisioner release settings with user_id completion event */
|
||||
ESP_BLE_MESH_PROVISIONER_DELETE_SETTINGS_WITH_INDEX_COMP_EVT, /*!< Provisioner delete settings with index completion event */
|
||||
ESP_BLE_MESH_PROVISIONER_DELETE_SETTINGS_WITH_USER_ID_COMP_EVT, /*!< Provisioner delete settings with user_id completion event */
|
||||
ESP_BLE_MESH_PROVISIONER_DRIECT_ERASE_SETTINGS_COMP_EVT, /*!< Provisioner directly erase settings completion event */
|
||||
ESP_BLE_MESH_PROVISIONER_START_RECV_HEARTBEAT_COMP_EVT, /*!< Provisioner start to receive Heartbeat message completion event */
|
||||
ESP_BLE_MESH_PROVISIONER_SET_HEARTBEAT_FILTER_TYPE_COMP_EVT, /*!< Provisioner set the filter type of receiving heartbeat message completion event */
|
||||
ESP_BLE_MESH_PROVISIONER_SET_HEARTBEAT_FILTER_INFO_COMP_EVT, /*!< Provisioner set the filter information of receiving heartbeat message completion event */
|
||||
@ -1217,6 +1218,12 @@ typedef union {
|
||||
int err_code; /*!< Indicate the result of deleting settings with user_id by the Provisioner */
|
||||
uint8_t index; /*!< Index of Provisioner settings */
|
||||
} provisioner_delete_settings_with_user_id_comp; /*!< Event parameters of ESP_BLE_MESH_PROVISIONER_DELETE_SETTINGS_WITH_USER_ID_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_PROVISIONER_DRIECT_ERASE_SETTINGS_COMP_EVT
|
||||
*/
|
||||
struct ble_mesh_provisioner_direct_erase_settings_comp_param {
|
||||
int err_code; /*!< Indicate the result of directly erasing settings by the Provisioner */
|
||||
} provisioner_direct_erase_settings_comp; /*!< Event parameters of ESP_BLE_MESH_PROVISIONER_DRIECT_ERASE_SETTINGS_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_PROVISIONER_START_RECV_HEARTBEAT_COMP_EVT
|
||||
*/
|
||||
|
@ -1890,6 +1890,12 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg)
|
||||
¶m.provisioner_delete_settings_with_user_id_comp.index);
|
||||
break;
|
||||
#endif /* CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE */
|
||||
#if CONFIG_BLE_MESH_SETTINGS
|
||||
case BTC_BLE_MESH_ACT_PROVISIONER_DIRECT_ERASE_SETTINGS:
|
||||
act = ESP_BLE_MESH_PROVISIONER_DRIECT_ERASE_SETTINGS_COMP_EVT;
|
||||
param.provisioner_direct_erase_settings_comp.err_code = bt_mesh_provisioner_direct_erase_settings();
|
||||
break;
|
||||
#endif /* CONFIG_BLE_MESH_SETTINGS */
|
||||
case BTC_BLE_MESH_ACT_PROVISIONER_START_RECV_HEARTBEAT:
|
||||
act = ESP_BLE_MESH_PROVISIONER_START_RECV_HEARTBEAT_COMP_EVT;
|
||||
param.provisioner_start_recv_heartbeat_comp.err_code =
|
||||
|
@ -66,6 +66,7 @@ typedef enum {
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_START_RECV_HEARTBEAT,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SET_HEARTBEAT_FILTER_TYPE,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_SET_HEARTBEAT_FILTER_INFO,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DIRECT_ERASE_SETTINGS,
|
||||
BTC_BLE_MESH_ACT_SET_FAST_PROV_INFO,
|
||||
BTC_BLE_MESH_ACT_SET_FAST_PROV_ACTION,
|
||||
BTC_BLE_MESH_ACT_LPN_ENABLE,
|
||||
|
@ -3189,6 +3189,7 @@ int bt_mesh_provisioner_release_settings_with_user_id(const char *user_id, bool
|
||||
|
||||
return provisioner_settings_release(idx, erase);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE */
|
||||
|
||||
static int role_erase(nvs_handle handle, const char *name)
|
||||
{
|
||||
@ -3518,6 +3519,7 @@ int bt_mesh_settings_erase_by_handle(nvs_handle handle)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
static int settings_user_id_delete(u8_t index)
|
||||
{
|
||||
char nvs_name[16] = {'\0'};
|
||||
@ -3639,6 +3641,37 @@ u8_t bt_mesh_provisioner_get_free_settings_user_id_count(void)
|
||||
return count;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE */
|
||||
|
||||
int bt_mesh_provisioner_direct_erase_settings(void)
|
||||
{
|
||||
nvs_handle handle = 0;
|
||||
int err = 0;
|
||||
|
||||
err = bt_mesh_settings_direct_open(&handle);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
for (int i = 0; i < ARRAY_SIZE(settings_name); i++) {
|
||||
err = settings_user_id_delete(i);
|
||||
if (err) {
|
||||
BT_ERR("%s, Failed to erase settings %d", __func__, i);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
bt_mesh_save_user_id_settings("mesh/uid", NULL, 0);
|
||||
#else
|
||||
err = bt_mesh_settings_erase_by_handle(handle);
|
||||
if (err) {
|
||||
BT_ERR("%s, Failed to erase settings", __func__);
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
bt_mesh_settings_direct_close();
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
||||
|
||||
int settings_core_init(void)
|
||||
|
@ -78,6 +78,7 @@ const char *bt_mesh_provisioner_get_settings_user_id(u8_t index);
|
||||
u8_t bt_mesh_provisioner_get_settings_index(const char *user_id);
|
||||
u8_t bt_mesh_provisioner_get_free_settings_user_id_count(void);
|
||||
#endif /* CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE */
|
||||
int bt_mesh_provisioner_direct_erase_settings(void);
|
||||
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
||||
|
||||
void bt_mesh_settings_lock(void);
|
||||
|
@ -80,6 +80,45 @@ void bt_mesh_settings_nvs_close(nvs_handle handle)
|
||||
nvs_close(handle);
|
||||
}
|
||||
|
||||
int bt_mesh_settings_direct_open(nvs_handle *handle)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
#if CONFIG_BLE_MESH_SPECIFIC_PARTITION
|
||||
err = nvs_flash_init_partition(CONFIG_BLE_MESH_PARTITION_NAME);
|
||||
if (err != ESP_OK) {
|
||||
BT_ERR("Failed to init partition %s, err %d", CONFIG_BLE_MESH_PARTITION_NAME, err);
|
||||
return -EIO;
|
||||
}
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(settings_ctx); i++) {
|
||||
struct settings_context *ctx = &settings_ctx[i];
|
||||
err = bt_mesh_settings_nvs_open(ctx->nvs_name, &ctx->handle);
|
||||
if (err) {
|
||||
BT_ERR("%s, Failed to open %s, err %d", __func__, ctx->nvs_name, err);
|
||||
return -EIO;
|
||||
}
|
||||
if (i == SETTINGS_CORE && handle) {
|
||||
*handle = ctx->handle;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bt_mesh_settings_direct_close(void)
|
||||
{
|
||||
for (int i = 0; i < ARRAY_SIZE(settings_ctx); i++) {
|
||||
struct settings_context *ctx = &settings_ctx[i];
|
||||
bt_mesh_settings_nvs_close(ctx->handle);
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_SPECIFIC_PARTITION
|
||||
nvs_flash_deinit_partition(CONFIG_BLE_MESH_PARTITION_NAME);
|
||||
#endif
|
||||
}
|
||||
|
||||
void bt_mesh_settings_foreach(void)
|
||||
{
|
||||
struct settings_context *ctx = NULL;
|
||||
|
@ -35,6 +35,9 @@ void bt_mesh_settings_deforeach(bool erase);
|
||||
int bt_mesh_settings_nvs_open(const char* name, nvs_handle *handle);
|
||||
void bt_mesh_settings_nvs_close(nvs_handle handle);
|
||||
|
||||
int bt_mesh_settings_direct_open(nvs_handle *handle);
|
||||
void bt_mesh_settings_direct_close(void);
|
||||
|
||||
int bt_mesh_save_settings(nvs_handle handle, const char *key, const u8_t *val, size_t len);
|
||||
int bt_mesh_load_settings(nvs_handle handle, const char *key, u8_t *buf, size_t buf_len, bool *exist);
|
||||
struct net_buf_simple *bt_mesh_get_settings_item(nvs_handle handle, const char *key);
|
||||
|
Loading…
Reference in New Issue
Block a user