1 /* 2 * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef _BLE_MESH_SETTINGS_NVS_H_ 8 #define _BLE_MESH_SETTINGS_NVS_H_ 9 10 #include "nvs_flash.h" 11 #include "mesh_buf.h" 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 typedef nvs_handle_t bt_mesh_nvs_handle_t; 18 19 #define SETTINGS_ITEM_SIZE sizeof(uint16_t) 20 21 #define BLE_MESH_GET_ELEM_IDX(x) ((uint8_t)((x) >> 8)) 22 #define BLE_MESH_GET_MODEL_IDX(x) ((uint8_t)(x)) 23 #define BLE_MESH_GET_MODEL_KEY(a, b) ((uint16_t)(((uint16_t)((a) << 8)) | (b))) 24 25 int bt_mesh_settings_nvs_open(const char* name, bt_mesh_nvs_handle_t *handle); 26 void bt_mesh_settings_nvs_close(bt_mesh_nvs_handle_t handle); 27 28 void bt_mesh_settings_init_foreach(void); 29 void bt_mesh_settings_deinit_foreach(bool erase); 30 31 int bt_mesh_settings_direct_open(bt_mesh_nvs_handle_t *handle); 32 void bt_mesh_settings_direct_close(void); 33 34 int bt_mesh_save_settings(bt_mesh_nvs_handle_t handle, const char *key, 35 const uint8_t *val, size_t len); 36 int bt_mesh_save_core_settings(const char *key, const uint8_t *val, size_t len); 37 int bt_mesh_save_uid_settings(const char *key, const uint8_t *val, size_t len); 38 39 int bt_mesh_erase_settings(bt_mesh_nvs_handle_t handle, const char *key); 40 int bt_mesh_erase_core_settings(const char *key); 41 int bt_mesh_erase_uid_settings(const char *name); 42 43 int bt_mesh_load_settings(bt_mesh_nvs_handle_t handle, const char *key, 44 uint8_t *buf, size_t buf_len, bool *exist); 45 int bt_mesh_load_core_settings(const char *key, uint8_t *buf, size_t buf_len, bool *exist); 46 int bt_mesh_load_uid_settings(const char *key, uint8_t *buf, size_t buf_len, bool *exist); 47 48 struct net_buf_simple *bt_mesh_get_settings_item(bt_mesh_nvs_handle_t handle, const char *key); 49 struct net_buf_simple *bt_mesh_get_core_settings_item(const char *key); 50 struct net_buf_simple *bt_mesh_get_uid_settings_item(const char *key); 51 52 int bt_mesh_add_settings_item(bt_mesh_nvs_handle_t handle, const char *key, const uint16_t val); 53 int bt_mesh_add_core_settings_item(const char *key, const uint16_t val); 54 int bt_mesh_add_uid_settings_item(const char *key, const uint16_t val); 55 56 int bt_mesh_remove_settings_item(bt_mesh_nvs_handle_t handle, const char *key, const uint16_t val); 57 int bt_mesh_remove_core_settings_item(const char *key, const uint16_t val); 58 int bt_mesh_remove_uid_settings_item(const char *key, const uint16_t val); 59 60 int bt_mesh_settings_erase_key(bt_mesh_nvs_handle_t handle, const char *key); 61 int bt_mesh_settings_erase_all(bt_mesh_nvs_handle_t handle); 62 63 #ifdef __cplusplus 64 } 65 #endif 66 67 #endif /* _BLE_MESH_SETTINGS_NVS_H_ */ 68