mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
ble_mesh: Provisioner supports multiple nvs namespaces
This commit is contained in:
parent
a58c272b8c
commit
8a7c8b2d60
@ -1858,6 +1858,37 @@ if BLE_MESH
|
||||
|
||||
if BLE_MESH_SETTINGS
|
||||
|
||||
if BLE_MESH_PROVISIONER
|
||||
|
||||
config BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
bool "Provisioner uses multiple NVS namespaces for BLE Mesh"
|
||||
default n
|
||||
help
|
||||
When selected, Provisioner can use different namespaces to store
|
||||
different instances of mesh information. For example, if in the
|
||||
first area, Provisioner uses NetKey A, AppKey A, etc. and provisions
|
||||
three devices, these information will be treated as mesh information
|
||||
instance A. When Provisioner is in the second area, it uses NetKey
|
||||
B, AppKey B, etc. and provisions two devices, then these information
|
||||
will be treated as mesh information instance B. Here instance A and
|
||||
instance B will be stored in different namespaces.
|
||||
And when this option is enabled, Provisioner needs to use specific
|
||||
functions to open the corresponding namespace, restore the mesh
|
||||
information or erase the mesh information.
|
||||
|
||||
if BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
|
||||
config BLE_MESH_MAX_NVS_NAMESPACE
|
||||
int "Maximum NVS namespaces supported by Provisioner"
|
||||
default 3
|
||||
range 1 255
|
||||
help
|
||||
This option specifies the maximum nvs namespaces supported by Provisioner.
|
||||
|
||||
endif # BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
|
||||
endif # BLE_MESH_PROVISIONER
|
||||
|
||||
config BLE_MESH_SPECIFIC_PARTITION
|
||||
bool "Use a specific NVS partition for BLE Mesh"
|
||||
default n
|
||||
@ -1873,7 +1904,7 @@ if BLE_MESH
|
||||
|
||||
config BLE_MESH_PARTITION_NAME
|
||||
string "Name of the NVS partition for BLE Mesh"
|
||||
default "BLE-MESH"
|
||||
default "ble_mesh"
|
||||
help
|
||||
This value defines the name of the specified NVS partition used by the
|
||||
mesh stack.
|
||||
|
@ -500,6 +500,225 @@ uint16_t esp_ble_mesh_provisioner_get_prov_node_count(void)
|
||||
return btc_ble_mesh_provisioner_get_prov_node_count();
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
esp_err_t esp_ble_mesh_provisioner_open_settings_with_index(uint8_t index)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (index >= CONFIG_BLE_MESH_MAX_NVS_NAMESPACE) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
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_OPEN_SETTINGS_WITH_INDEX;
|
||||
|
||||
arg.open_settings_with_index.index = index;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_open_settings_with_user_id(const char *user_id)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!user_id || strlen(user_id) > ESP_BLE_MESH_SETTINGS_USER_ID_SIZE) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
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_OPEN_SETTINGS_WITH_USER_ID;
|
||||
|
||||
strncpy(arg.open_settings_with_user_id.user_id, user_id, strlen(user_id));
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_close_settings_with_index(uint8_t index)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (index >= CONFIG_BLE_MESH_MAX_NVS_NAMESPACE) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
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_CLOSE_SETTINGS_WITH_INDEX;
|
||||
|
||||
arg.close_settings_with_index.index = index;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_close_settings_with_user_id(const char *user_id)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!user_id || strlen(user_id) > ESP_BLE_MESH_SETTINGS_USER_ID_SIZE) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
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_CLOSE_SETTINGS_WITH_USER_ID;
|
||||
|
||||
strncpy(arg.close_settings_with_user_id.user_id, user_id, strlen(user_id));
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_restore_settings_with_index(uint8_t index)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (index >= CONFIG_BLE_MESH_MAX_NVS_NAMESPACE) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
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_RESTORE_SETTINGS_WITH_INDEX;
|
||||
|
||||
arg.restore_settings_with_index.index = index;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_restore_settings_with_user_id(const char *user_id)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!user_id || strlen(user_id) > ESP_BLE_MESH_SETTINGS_USER_ID_SIZE) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
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_RESTORE_SETTINGS_WITH_USER_ID;
|
||||
|
||||
strncpy(arg.restore_settings_with_user_id.user_id, user_id, strlen(user_id));
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_release_settings_with_index(uint8_t index, bool erase)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (index >= CONFIG_BLE_MESH_MAX_NVS_NAMESPACE) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
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_RELEASE_SETTINGS_WITH_INDEX;
|
||||
|
||||
arg.release_settings_with_index.index = index;
|
||||
arg.release_settings_with_index.erase = erase;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_release_settings_with_user_id(const char *user_id, bool erase)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!user_id || strlen(user_id) > ESP_BLE_MESH_SETTINGS_USER_ID_SIZE) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
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_RELEASE_SETTINGS_WITH_USER_ID;
|
||||
|
||||
strncpy(arg.release_settings_with_user_id.user_id, user_id, strlen(user_id));
|
||||
arg.release_settings_with_user_id.erase = erase;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_delete_settings_with_index(uint8_t index)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (index >= CONFIG_BLE_MESH_MAX_NVS_NAMESPACE) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
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_DELETE_SETTINGS_WITH_INDEX;
|
||||
|
||||
arg.delete_settings_with_index.index = index;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_delete_settings_with_user_id(const char *user_id)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!user_id || strlen(user_id) > ESP_BLE_MESH_SETTINGS_USER_ID_SIZE) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
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_DELETE_SETTINGS_WITH_USER_ID;
|
||||
|
||||
strncpy(arg.delete_settings_with_user_id.user_id, user_id, strlen(user_id));
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
const char *esp_ble_mesh_provisioner_get_settings_user_id(uint8_t index)
|
||||
{
|
||||
return btc_ble_mesh_provisioner_get_settings_user_id(index);
|
||||
}
|
||||
|
||||
uint8_t esp_ble_mesh_provisioner_get_settings_index(const char *user_id)
|
||||
{
|
||||
return btc_ble_mesh_provisioner_get_settings_index(user_id);
|
||||
}
|
||||
|
||||
uint8_t esp_ble_mesh_provisioner_get_free_settings_user_id_count(void)
|
||||
{
|
||||
return btc_ble_mesh_provisioner_get_free_settings_user_id_count();
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE */
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
||||
|
||||
#if (CONFIG_BLE_MESH_FAST_PROV)
|
||||
|
@ -370,6 +370,237 @@ const uint8_t *esp_ble_mesh_provisioner_get_local_net_key(uint16_t net_idx);
|
||||
*/
|
||||
uint16_t esp_ble_mesh_provisioner_get_prov_node_count(void);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to open the corresponding
|
||||
* flash section for storing mesh provisioning information.
|
||||
*
|
||||
* @note 1. Provisioner can use this function to open a flash section for
|
||||
* storing mesh information.
|
||||
* 2. And before calling any of restore, release and close functions,
|
||||
* the open function must be called firstly.
|
||||
*
|
||||
* @param[in] index: Provisioner settings index.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_open_settings_with_index(uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to open the corresponding
|
||||
* flash section for storing mesh provisioning information.
|
||||
*
|
||||
* @note 1. Provisioner can use this function to open a flash section for
|
||||
* storing mesh information.
|
||||
* 2. And before calling any of restore, release and close functions,
|
||||
* the open function must be called firstly.
|
||||
*
|
||||
* @param[in] user_id: User id of Provisioner settings.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_open_settings_with_user_id(const char *user_id);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to close the corresponding
|
||||
* flash section which has been opened previously for storing mesh
|
||||
* provisioning information.
|
||||
*
|
||||
* @note 1. Before closing the flash section, it must has been opened previously.
|
||||
* 2. When the release function is invoked, and the "erase" flag is set to
|
||||
* false, then calling the close function will only close the flash section.
|
||||
* And if the "erase" flag is set to true, besides closing the flash section,
|
||||
* the corresponding settings user_id will also be cleaned and erased.
|
||||
*
|
||||
* @param[in] index: Provisioner settings index.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_close_settings_with_index(uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to close the corresponding
|
||||
* flash section which has been opened previously for storing mesh
|
||||
* provisioning information.
|
||||
*
|
||||
* @note 1. Before closing the flash section, it must has been opened previously.
|
||||
* 2. When the release function is invoked, and the "erase" flag is set to
|
||||
* false, then calling the close function will only close the flash section.
|
||||
* And if the "erase" flag is set to true, besides closing the flash section,
|
||||
* the corresponding settings user_id will also be cleaned and erased.
|
||||
*
|
||||
* @param[in] user_id: User id of Provisioner settings.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_close_settings_with_user_id(const char *user_id);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to restore the mesh provisioning
|
||||
* information from the corresponding flash section which has been opened
|
||||
* previously.
|
||||
*
|
||||
* @note 1. Before calling this function to restore corresponding mesh information,
|
||||
* the previously restored mesh information must be released using the release
|
||||
* function.
|
||||
* 2. And the flash section must has been opened using the open function.
|
||||
*
|
||||
* @param[in] index: Provisioner settings index.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_restore_settings_with_index(uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to restore the mesh provisioning
|
||||
* information from the corresponding flash section which has been opened
|
||||
* previously.
|
||||
*
|
||||
* @note 1. Before calling this function to restore corresponding mesh information,
|
||||
* the previously restored mesh information must be released using the release
|
||||
* function.
|
||||
* 2. And the flash section must has been opened using the open function.
|
||||
*
|
||||
* @param[in] user_id: User id of Provisioner settings.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_restore_settings_with_user_id(const char *user_id);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to release the mesh provisioning
|
||||
* information which has been restored from the corresponding flash section.
|
||||
*
|
||||
* @note 1. When this function is called, if the "erase" flag is set to false, the
|
||||
* restored mesh information will be cleaned (e.g. removing the NetKey, etc).
|
||||
* If the "erase" flag is set to true, besides cleaning the mesh information,
|
||||
* the mesh information stored in the flash section will also be erased. And
|
||||
* this function will also disable the Provisioner functionality internally.
|
||||
* 2. If Provisioner tries to work properly again, the restored function must
|
||||
* be invoked to restore mesh information from this flash section if the mesh
|
||||
* information is not erased, or from another flash section if erased.
|
||||
* Before calling this, the open and restore functions must be invoked.
|
||||
* 3. The whole working process of Provisioner settings should be as following:
|
||||
* a) open settings A
|
||||
* b) restore settings A
|
||||
* c) start to provision and control nodes
|
||||
* d) release settings A
|
||||
* e) close settings A
|
||||
* f) open settings B
|
||||
* g) restore settings B
|
||||
* h) start to provision and control other nodes
|
||||
* i) release settings B
|
||||
* j) close settings B
|
||||
* k) ......
|
||||
*
|
||||
* @param[in] index: Provisioner settings index.
|
||||
* @param[in] erase: Indicate whether erase the information from flash.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_release_settings_with_index(uint8_t index, bool erase);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to release the mesh provisioning
|
||||
* information which has been restored from the corresponding flash section.
|
||||
*
|
||||
* @note 1. When this function is called, if the "erase" flag is set to false, the
|
||||
* restored mesh information will be cleaned (e.g. removing the NetKey, etc).
|
||||
* If the "erase" flag is set to true, besides cleaning the mesh information,
|
||||
* the mesh information stored in the flash section will also be erased. And
|
||||
* this function will also disable the Provisioner functionality internally.
|
||||
* 2. If Provisioner tries to work properly again, the restored function must
|
||||
* be invoked to restore mesh information from this flash section if the mesh
|
||||
* information is not erased, or from another flash section if erased.
|
||||
* Before calling this, the open and restore functions must be invoked.
|
||||
* 3. The whole working process of Provisioner settings should be as following:
|
||||
* a) open settings A
|
||||
* b) restore settings A
|
||||
* c) start to provision and control nodes
|
||||
* d) release settings A
|
||||
* e) close settings A
|
||||
* f) open settings B
|
||||
* g) restore settings B
|
||||
* h) start to provision and control other nodes
|
||||
* i) release settings B
|
||||
* j) close settings B
|
||||
* k) ......
|
||||
*
|
||||
* @param[in] user_id: User id of Provisioner settings.
|
||||
* @param[in] erase: Indicate whether erase the information from flash.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_release_settings_with_user_id(const char *user_id, bool erase);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to erase the mesh provisioning
|
||||
* information which is not been restored, and the corrseponding settings
|
||||
* user_id from the flash section.
|
||||
*
|
||||
* @note When this function is called, the corresponding nvs namespace must not
|
||||
* be open and restored. This function is used to erase the mesh information
|
||||
* and settings user_id which are not been used currently.
|
||||
*
|
||||
* @param[in] index: Provisioner settings index.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_delete_settings_with_index(uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to erase the mesh provisioning
|
||||
* information which is not been restored, and the corrseponding settings
|
||||
* user_id from the flash section.
|
||||
*
|
||||
* @note When this function is called, the corresponding nvs namespace must not
|
||||
* be open and restored. This function is used to erase the mesh information
|
||||
* and settings user_id which are not been used currently.
|
||||
*
|
||||
* @param[in] index: Provisioner settings index.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_delete_settings_with_user_id(const char *user_id);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to get the settings user id.
|
||||
*
|
||||
* @param[in] index: Provisioner settings index.
|
||||
*
|
||||
* @return User id on success or NULL on failure.
|
||||
*
|
||||
*/
|
||||
const char *esp_ble_mesh_provisioner_get_settings_user_id(uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to get the settings index.
|
||||
*
|
||||
* @param[in] user_id: User id of Provisioner settings.
|
||||
*
|
||||
* @return Provisioner Settings index.
|
||||
*
|
||||
*/
|
||||
uint8_t esp_ble_mesh_provisioner_get_settings_index(const char *user_id);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to get the number of free
|
||||
* settings user_id.
|
||||
*
|
||||
* @return Number of free Provisioner Settings.
|
||||
*
|
||||
*/
|
||||
uint8_t esp_ble_mesh_provisioner_get_free_settings_user_id_count(void);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get fast provisioning application key.
|
||||
*
|
||||
|
@ -40,6 +40,12 @@
|
||||
/*!< The maximum length of a BLE Mesh unprovisioned device name */
|
||||
#define ESP_BLE_MESH_DEVICE_NAME_MAX_LEN DEVICE_NAME_SIZE
|
||||
|
||||
/*!< The maximum length of the settings user_id of Provisioner */
|
||||
#define ESP_BLE_MESH_SETTINGS_USER_ID_SIZE 20
|
||||
|
||||
/*!< Invalid settings index of Provisioner */
|
||||
#define ESP_BLE_MESH_INVALID_SETTINGS_INDEX 0xFF
|
||||
|
||||
/*!< Define the BLE Mesh octet 16 bytes size */
|
||||
#define ESP_BLE_MESH_OCTET16_LEN 16
|
||||
typedef uint8_t esp_ble_mesh_octet16_t[ESP_BLE_MESH_OCTET16_LEN];
|
||||
@ -773,6 +779,16 @@ typedef enum {
|
||||
ESP_BLE_MESH_PROVISIONER_STORE_NODE_COMP_DATA_COMP_EVT, /*!< Provisioner store node composition data completion event */
|
||||
ESP_BLE_MESH_PROVISIONER_DELETE_NODE_WITH_UUID_COMP_EVT, /*!< Provisioner delete node with uuid completion event */
|
||||
ESP_BLE_MESH_PROVISIONER_DELETE_NODE_WITH_ADDR_COMP_EVT, /*!< Provisioner delete node with unicast address completion event */
|
||||
ESP_BLE_MESH_PROVISIONER_OPEN_SETTINGS_WITH_INDEX_COMP_EVT, /*!< Provisioner open settings with index completion event */
|
||||
ESP_BLE_MESH_PROVISIONER_OPEN_SETTINGS_WITH_USER_ID_COMP_EVT, /*!< Provisioner open settings with user_id completion event */
|
||||
ESP_BLE_MESH_PROVISIONER_CLOSE_SETTINGS_WITH_INDEX_COMP_EVT, /*!< Provisioner close settings with index completion event */
|
||||
ESP_BLE_MESH_PROVISIONER_CLOSE_SETTINGS_WITH_USER_ID_COMP_EVT, /*!< Provisioner close settings with user_id completion event */
|
||||
ESP_BLE_MESH_PROVISIONER_RESTORE_SETTINGS_WITH_INDEX_COMP_EVT, /*!< Provisioner restore settings with index completion event */
|
||||
ESP_BLE_MESH_PROVISIONER_RESTORE_SETTINGS_WITH_USER_ID_COMP_EVT, /*!< Provisioner restore settings with user_id completion event */
|
||||
ESP_BLE_MESH_PROVISIONER_RELEASE_SETTINGS_WITH_INDEX_COMP_EVT, /*!< Provisioner release settings with index completion event */
|
||||
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_SET_FAST_PROV_INFO_COMP_EVT, /*!< Set fast provisioning information (e.g. unicast address range, net_idx, etc.) completion event */
|
||||
ESP_BLE_MESH_SET_FAST_PROV_ACTION_COMP_EVT, /*!< Set fast provisioning action completion event */
|
||||
ESP_BLE_MESH_HEARTBEAT_MESSAGE_RECV_EVT, /*!< Receive Heartbeat message event */
|
||||
@ -1098,17 +1114,87 @@ typedef union {
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_PROVISIONER_DELETE_NODE_WITH_UUID_COMP_EVT
|
||||
*/
|
||||
struct ble_mesh_provisioner_delete_node_with_uuid_comp_data_comp_param {
|
||||
struct ble_mesh_provisioner_delete_node_with_uuid_comp_param {
|
||||
int err_code; /*!< Indicate the result of deleting node with uuid by the Provisioner */
|
||||
uint8_t uuid[16]; /*!< Node device uuid */
|
||||
} provisioner_delete_node_with_uuid_comp; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_DELETE_NODE_WITH_UUID_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_PROVISIONER_DELETE_NODE_WITH_ADDR_COMP_EVT
|
||||
*/
|
||||
struct ble_mesh_provisioner_delete_node_with_addr_comp_data_comp_param {
|
||||
struct ble_mesh_provisioner_delete_node_with_addr_comp_param {
|
||||
int err_code; /*!< Indicate the result of deleting node with unicast address by the Provisioner */
|
||||
uint16_t unicast_addr; /*!< Node unicast address */
|
||||
} provisioner_delete_node_with_addr_comp; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_DELETE_NODE_WITH_ADDR_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_PROVISIONER_OPEN_SETTINGS_WITH_INDEX_COMP_EVT
|
||||
*/
|
||||
struct ble_mesh_provisioner_open_settings_with_index_comp_param {
|
||||
int err_code; /*!< Indicate the result of opening settings with index by the Provisioner */
|
||||
uint8_t index; /*!< Index of Provisioner settings */
|
||||
} provisioner_open_settings_with_index_comp; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_OPEN_SETTINGS_WITH_INDEX_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_PROVISIONER_OPEN_SETTINGS_WITH_USER_ID_COMP_EVT
|
||||
*/
|
||||
struct ble_mesh_provisioner_open_settings_with_user_id_comp_param {
|
||||
int err_code; /*!< Indicate the result of opening settings with user_id by the Provisioner */
|
||||
uint8_t index; /*!< Index of Provisioner settings */
|
||||
} provisioner_open_settings_with_user_id_comp; /* !< Event parameters of ESP_BLE_MESH_PROVISIONER_OPEN_SETTINGS_WITH_USER_ID_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_PROVISIONER_CLOSE_SETTINGS_WITH_INDEX_COMP_EVT
|
||||
*/
|
||||
struct ble_mesh_provisioner_close_settings_with_index_comp_param {
|
||||
int err_code; /*!< Indicate the result of closing settings with index by the Provisioner */
|
||||
uint8_t index; /*!< Index of Provisioner settings */
|
||||
} provisioner_close_settings_with_index_comp; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_CLOSE_SETTINGS_WITH_INDEX_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_PROVISIONER_CLOSE_SETTINGS_WITH_USER_ID_COMP_EVT
|
||||
*/
|
||||
struct ble_mesh_provisioner_close_settings_with_user_id_comp_param {
|
||||
int err_code; /*!< Indicate the result of closing settings with user_id by the Provisioner */
|
||||
uint8_t index; /*!< Index of Provisioner settings */
|
||||
} provisioner_close_settings_with_user_id_comp; /*!< Event parameters of ESP_BLE_MESH_PROVISIONER_CLOSE_SETTINGS_WITH_USER_ID_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_PROVISIONER_RESTORE_SETTINGS_WITH_INDEX_COMP_EVT
|
||||
*/
|
||||
struct ble_mesh_provisioner_restore_settings_with_index_comp_param {
|
||||
int err_code; /*!< Indicate the result of restoring settings with index by the Provisioner */
|
||||
uint8_t index; /*!< Index of Provisioner settings */
|
||||
} provisioner_restore_settings_with_index_comp; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_RESTORE_SETTINGS_WITH_INDEX_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_PROVISIONER_RESTORE_SETTINGS_WITH_USER_ID_COMP_EVT
|
||||
*/
|
||||
struct ble_mesh_provisioner_restore_settings_with_user_id_comp_param {
|
||||
int err_code; /*!< Indicate the result of restoring settings with user_id by the Provisioner */
|
||||
uint8_t index; /*!< Index of Provisioner settings */
|
||||
} provisioner_restore_settings_with_user_id_comp; /*!< Event parameters of ESP_BLE_MESH_PROVISIONER_RESTORE_SETTINGS_WITH_USER_ID_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_PROVISIONER_RELEASE_SETTINGS_WITH_INDEX_COMP_EVT
|
||||
*/
|
||||
struct ble_mesh_provisioner_release_settings_with_index_comp_param {
|
||||
int err_code; /*!< Indicate the result of releasing settings with index by the Provisioner */
|
||||
uint8_t index; /*!< Index of Provisioner settings */
|
||||
} provisioner_release_settings_with_index_comp; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_RELEASE_SETTINGS_WITH_INDEX_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_PROVISIONER_RELEASE_SETTINGS_WITH_USER_ID_COMP_EVT
|
||||
*/
|
||||
struct ble_mesh_provisioner_release_settings_with_user_id_comp_param {
|
||||
int err_code; /*!< Indicate the result of releasing settings with user_id by the Provisioner */
|
||||
uint8_t index; /*!< Index of Provisioner settings */
|
||||
} provisioner_release_settings_with_user_id_comp; /*!< Event parameters of ESP_BLE_MESH_PROVISIONER_RELEASE_SETTINGS_WITH_USER_ID_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_PROVISIONER_DELETE_SETTINGS_WITH_INDEX_COMP_EVT
|
||||
*/
|
||||
struct ble_mesh_provisioner_delete_settings_with_index_comp_param {
|
||||
int err_code; /*!< Indicate the result of deleting settings with index by the Provisioner */
|
||||
uint8_t index; /*!< Index of Provisioner settings */
|
||||
} provisioner_delete_settings_with_index_comp; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_DELETE_SETTINGS_WITH_INDEX_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_PROVISIONER_DELETE_SETTINGS_WITH_USER_ID_COMP_EVT
|
||||
*/
|
||||
struct ble_mesh_provisioner_delete_settings_with_user_id_comp_param {
|
||||
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_SET_FAST_PROV_INFO_COMP_EVT
|
||||
*/
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "time_scene_client.h"
|
||||
#include "client_common.h"
|
||||
#include "state_binding.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "btc_ble_mesh_prov.h"
|
||||
#include "btc_ble_mesh_config_model.h"
|
||||
@ -782,6 +783,27 @@ esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_addr(uint16_t unicas
|
||||
return (esp_ble_mesh_node_t *)bt_mesh_provisioner_get_node_with_addr(unicast_addr);
|
||||
}
|
||||
|
||||
u16_t btc_ble_mesh_provisioner_get_prov_node_count(void)
|
||||
{
|
||||
return bt_mesh_provisioner_get_prov_node_count();
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
const char *btc_ble_mesh_provisioner_get_settings_user_id(uint8_t index)
|
||||
{
|
||||
return bt_mesh_provisioner_get_settings_user_id(index);
|
||||
}
|
||||
|
||||
uint8_t btc_ble_mesh_provisioner_get_settings_index(const char *user_id)
|
||||
{
|
||||
return bt_mesh_provisioner_get_settings_index(user_id);
|
||||
}
|
||||
|
||||
uint8_t btc_ble_mesh_provisioner_get_free_settings_user_id_count(void)
|
||||
{
|
||||
return bt_mesh_provisioner_get_free_settings_user_id_count();
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE */
|
||||
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
||||
|
||||
static void btc_ble_mesh_heartbeat_msg_recv_cb(u8_t hops, u16_t feature)
|
||||
@ -996,11 +1018,6 @@ const esp_ble_mesh_comp_t *btc_ble_mesh_comp_get(void)
|
||||
return (const esp_ble_mesh_comp_t *)bt_mesh_comp_get();
|
||||
}
|
||||
|
||||
u16_t btc_ble_mesh_provisioner_get_prov_node_count(void)
|
||||
{
|
||||
return bt_mesh_provisioner_get_prov_node_count();
|
||||
}
|
||||
|
||||
/* Configuration Models */
|
||||
extern const struct bt_mesh_model_op bt_mesh_cfg_srv_op[];
|
||||
extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[];
|
||||
@ -1789,6 +1806,71 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg)
|
||||
param.provisioner_delete_node_with_addr_comp.err_code =
|
||||
bt_mesh_provisioner_delete_node_with_addr(arg->delete_node_with_addr.unicast_addr);
|
||||
break;
|
||||
#if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
case BTC_BLE_MESH_ACT_PROVISIONER_OPEN_SETTINGS_WITH_INDEX:
|
||||
act = ESP_BLE_MESH_PROVISIONER_OPEN_SETTINGS_WITH_INDEX_COMP_EVT;
|
||||
param.provisioner_open_settings_with_index_comp.index = arg->open_settings_with_index.index;
|
||||
param.provisioner_open_settings_with_index_comp.err_code =
|
||||
bt_mesh_provisioner_open_settings_with_index(arg->open_settings_with_index.index);
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_PROVISIONER_OPEN_SETTINGS_WITH_USER_ID:
|
||||
act = ESP_BLE_MESH_PROVISIONER_OPEN_SETTINGS_WITH_USER_ID_COMP_EVT;
|
||||
param.provisioner_open_settings_with_user_id_comp.err_code =
|
||||
bt_mesh_provisioner_open_settings_with_user_id(arg->open_settings_with_user_id.user_id,
|
||||
¶m.provisioner_open_settings_with_user_id_comp.index);
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_PROVISIONER_CLOSE_SETTINGS_WITH_INDEX:
|
||||
act = ESP_BLE_MESH_PROVISIONER_CLOSE_SETTINGS_WITH_INDEX_COMP_EVT;
|
||||
param.provisioner_close_settings_with_index_comp.index = arg->close_settings_with_index.index;
|
||||
param.provisioner_close_settings_with_index_comp.err_code =
|
||||
bt_mesh_provisioner_close_settings_with_index(arg->close_settings_with_index.index);
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_PROVISIONER_CLOSE_SETTINGS_WITH_USER_ID:
|
||||
act = ESP_BLE_MESH_PROVISIONER_CLOSE_SETTINGS_WITH_USER_ID_COMP_EVT;
|
||||
param.provisioner_close_settings_with_user_id_comp.err_code =
|
||||
bt_mesh_provisioner_close_settings_with_user_id(arg->close_settings_with_user_id.user_id,
|
||||
¶m.provisioner_close_settings_with_user_id_comp.index);
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_PROVISIONER_RESTORE_SETTINGS_WITH_INDEX:
|
||||
act = ESP_BLE_MESH_PROVISIONER_RESTORE_SETTINGS_WITH_INDEX_COMP_EVT;
|
||||
param.provisioner_restore_settings_with_index_comp.index = arg->restore_settings_with_index.index;
|
||||
param.provisioner_restore_settings_with_index_comp.err_code =
|
||||
bt_mesh_provisioner_restore_settings_with_index(arg->restore_settings_with_index.index);
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_PROVISIONER_RESTORE_SETTINGS_WITH_USER_ID:
|
||||
act = ESP_BLE_MESH_PROVISIONER_RESTORE_SETTINGS_WITH_USER_ID_COMP_EVT;
|
||||
param.provisioner_restore_settings_with_user_id_comp.err_code =
|
||||
bt_mesh_provisioner_restore_settings_with_user_id(arg->restore_settings_with_user_id.user_id,
|
||||
¶m.provisioner_restore_settings_with_user_id_comp.index);
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_PROVISIONER_RELEASE_SETTINGS_WITH_INDEX:
|
||||
act = ESP_BLE_MESH_PROVISIONER_RELEASE_SETTINGS_WITH_INDEX_COMP_EVT;
|
||||
param.provisioner_release_settings_with_index_comp.index = arg->release_settings_with_index.index;
|
||||
param.provisioner_release_settings_with_index_comp.err_code =
|
||||
bt_mesh_provisioner_release_settings_with_index(
|
||||
arg->release_settings_with_index.index, arg->release_settings_with_index.erase);
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_PROVISIONER_RELEASE_SETTINGS_WITH_USER_ID:
|
||||
act = ESP_BLE_MESH_PROVISIONER_RELEASE_SETTINGS_WITH_USER_ID_COMP_EVT;
|
||||
param.provisioner_release_settings_with_user_id_comp.err_code =
|
||||
bt_mesh_provisioner_release_settings_with_user_id(
|
||||
arg->release_settings_with_user_id.user_id, arg->release_settings_with_user_id.erase,
|
||||
¶m.provisioner_release_settings_with_user_id_comp.index);
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_PROVISIONER_DELETE_SETTINGS_WITH_INDEX:
|
||||
act = ESP_BLE_MESH_PROVISIONER_DELETE_SETTINGS_WITH_INDEX_COMP_EVT;
|
||||
param.provisioner_delete_settings_with_index_comp.index = arg->delete_settings_with_index.index;
|
||||
param.provisioner_delete_settings_with_index_comp.err_code =
|
||||
bt_mesh_provisioner_delete_settings_with_index(arg->delete_settings_with_index.index);
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_PROVISIONER_DELETE_SETTINGS_WITH_USER_ID:
|
||||
act = ESP_BLE_MESH_PROVISIONER_DELETE_SETTINGS_WITH_USER_ID_COMP_EVT;
|
||||
param.provisioner_delete_settings_with_user_id_comp.err_code =
|
||||
bt_mesh_provisioner_delete_settings_with_user_id(
|
||||
arg->delete_settings_with_user_id.user_id,
|
||||
¶m.provisioner_delete_settings_with_user_id_comp.index);
|
||||
break;
|
||||
#endif /* CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE */
|
||||
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
||||
#if CONFIG_BLE_MESH_FAST_PROV
|
||||
case BTC_BLE_MESH_ACT_SET_FAST_PROV_INFO:
|
||||
|
@ -53,6 +53,16 @@ typedef enum {
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_STORE_NODE_COMP_DATA,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DELETE_NODE_WITH_UUID,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DELETE_NODE_WITH_ADDR,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_OPEN_SETTINGS_WITH_INDEX,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_OPEN_SETTINGS_WITH_USER_ID,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_CLOSE_SETTINGS_WITH_INDEX,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_CLOSE_SETTINGS_WITH_USER_ID,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_RESTORE_SETTINGS_WITH_INDEX,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_RESTORE_SETTINGS_WITH_USER_ID,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_RELEASE_SETTINGS_WITH_INDEX,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_RELEASE_SETTINGS_WITH_USER_ID,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DELETE_SETTINGS_WITH_INDEX,
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_DELETE_SETTINGS_WITH_USER_ID,
|
||||
BTC_BLE_MESH_ACT_SET_FAST_PROV_INFO,
|
||||
BTC_BLE_MESH_ACT_SET_FAST_PROV_ACTION,
|
||||
BTC_BLE_MESH_ACT_LPN_ENABLE,
|
||||
@ -187,6 +197,38 @@ typedef union {
|
||||
struct ble_mesh_provisioner_delete_node_with_addr_args {
|
||||
uint16_t unicast_addr;
|
||||
} delete_node_with_addr;
|
||||
struct ble_mesh_provisioner_open_settings_with_index_args {
|
||||
uint8_t index;
|
||||
} open_settings_with_index;
|
||||
struct ble_mesh_provisioner_open_settings_with_user_id_args {
|
||||
char user_id[ESP_BLE_MESH_SETTINGS_USER_ID_SIZE + 1];
|
||||
} open_settings_with_user_id;
|
||||
struct ble_mesh_provisioner_close_settings_with_index_args {
|
||||
uint8_t index;
|
||||
} close_settings_with_index;
|
||||
struct ble_mesh_provisioner_close_settings_with_user_id_args {
|
||||
char user_id[ESP_BLE_MESH_SETTINGS_USER_ID_SIZE + 1];
|
||||
} close_settings_with_user_id;
|
||||
struct ble_mesh_provisioner_restore_settings_with_index_args {
|
||||
uint8_t index;
|
||||
} restore_settings_with_index;
|
||||
struct ble_mesh_provisioner_restore_settings_with_user_id_args {
|
||||
char user_id[ESP_BLE_MESH_SETTINGS_USER_ID_SIZE + 1];
|
||||
} restore_settings_with_user_id;
|
||||
struct ble_mesh_provisioner_release_settings_with_index_args {
|
||||
uint8_t index;
|
||||
bool erase;
|
||||
} release_settings_with_index;
|
||||
struct ble_mesh_provisioner_release_settings_with_user_id_args {
|
||||
char user_id[ESP_BLE_MESH_SETTINGS_USER_ID_SIZE + 1];
|
||||
bool erase;
|
||||
} release_settings_with_user_id;
|
||||
struct ble_mesh_provisioner_delete_settings_with_index_args {
|
||||
uint8_t index;
|
||||
} delete_settings_with_index;
|
||||
struct ble_mesh_provisioner_delete_settings_with_user_id_args {
|
||||
char user_id[ESP_BLE_MESH_SETTINGS_USER_ID_SIZE + 1];
|
||||
} delete_settings_with_user_id;
|
||||
struct ble_mesh_set_fast_prov_info_args {
|
||||
uint16_t unicast_min;
|
||||
uint16_t unicast_max;
|
||||
@ -292,6 +334,10 @@ const esp_ble_mesh_comp_t *btc_ble_mesh_comp_get(void);
|
||||
|
||||
u16_t btc_ble_mesh_provisioner_get_prov_node_count(void);
|
||||
|
||||
const char *btc_ble_mesh_provisioner_get_settings_user_id(uint8_t index);
|
||||
uint8_t btc_ble_mesh_provisioner_get_settings_index(const char *user_id);
|
||||
uint8_t btc_ble_mesh_provisioner_get_free_settings_user_id_count(void);
|
||||
|
||||
void btc_ble_mesh_model_call_handler(btc_msg_t *msg);
|
||||
void btc_ble_mesh_model_cb_handler(btc_msg_t *msg);
|
||||
|
||||
|
@ -244,6 +244,11 @@ void bt_mesh_model_foreach(void (*func)(struct bt_mesh_model *mod,
|
||||
{
|
||||
int i, j;
|
||||
|
||||
if (dev_comp == NULL) {
|
||||
BT_ERR("%s, NULL dev_comp", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < dev_comp->elem_count; i++) {
|
||||
struct bt_mesh_elem *elem = &dev_comp->elem[i];
|
||||
|
||||
|
@ -62,10 +62,10 @@ static const u8_t adv_type[] = {
|
||||
[BLE_MESH_ADV_URI] = BLE_MESH_DATA_URI,
|
||||
};
|
||||
|
||||
NET_BUF_POOL_DEFINE(adv_buf_pool, CONFIG_BLE_MESH_ADV_BUF_COUNT + 3 * CONFIG_BLE_MESH_PBA_SAME_TIME,
|
||||
NET_BUF_POOL_DEFINE(adv_buf_pool, CONFIG_BLE_MESH_ADV_BUF_COUNT,
|
||||
BLE_MESH_ADV_DATA_SIZE, BLE_MESH_ADV_USER_DATA_SIZE, NULL);
|
||||
|
||||
static struct bt_mesh_adv adv_pool[CONFIG_BLE_MESH_ADV_BUF_COUNT + 3 * CONFIG_BLE_MESH_PBA_SAME_TIME];
|
||||
static struct bt_mesh_adv adv_pool[CONFIG_BLE_MESH_ADV_BUF_COUNT];
|
||||
|
||||
struct bt_mesh_queue {
|
||||
QueueHandle_t queue;
|
||||
@ -76,7 +76,8 @@ struct bt_mesh_queue {
|
||||
};
|
||||
|
||||
static struct bt_mesh_queue xBleMeshQueue;
|
||||
#define BLE_MESH_QUEUE_SIZE 150
|
||||
/* We reserve one queue for bt_mesh_adv_update() */
|
||||
#define BLE_MESH_QUEUE_SIZE (CONFIG_BLE_MESH_ADV_BUF_COUNT + 1)
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
|
||||
NET_BUF_POOL_DEFINE(relay_adv_buf_pool, CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT,
|
||||
@ -85,7 +86,7 @@ NET_BUF_POOL_DEFINE(relay_adv_buf_pool, CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT,
|
||||
static struct bt_mesh_adv relay_adv_pool[CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT];
|
||||
|
||||
static struct bt_mesh_queue xBleMeshRelayQueue;
|
||||
#define BLE_MESH_RELAY_QUEUE_SIZE 150
|
||||
#define BLE_MESH_RELAY_QUEUE_SIZE CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT
|
||||
|
||||
static QueueSetHandle_t xBleMeshQueueSet;
|
||||
#define BLE_MESH_QUEUE_SET_SIZE (BLE_MESH_QUEUE_SIZE + BLE_MESH_RELAY_QUEUE_SIZE)
|
||||
|
@ -42,6 +42,8 @@
|
||||
|
||||
static struct k_delayed_work beacon_timer;
|
||||
|
||||
static bool ready_to_send(void);
|
||||
|
||||
static struct bt_mesh_subnet *cache_check(u8_t data[21])
|
||||
{
|
||||
size_t subnet_size = 0U;
|
||||
@ -75,6 +77,16 @@ static void beacon_complete(int err, void *user_data)
|
||||
|
||||
BT_DBG("err %d", err);
|
||||
|
||||
/* Care should be taken here, since the user_data is the
|
||||
* pointer of a subnet. When the device is a Provisioner,
|
||||
* its subnet is allocated dynamically. And if the
|
||||
* corresponding subnet has been removed, this will cause
|
||||
* exception here.
|
||||
*/
|
||||
if (ready_to_send() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
sub->beacon_sent = k_uptime_get_32();
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ static void clear_friendship(bool force, bool disable)
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_rx_reset();
|
||||
bt_mesh_rx_reset(true);
|
||||
|
||||
k_delayed_work_cancel(&lpn->timer);
|
||||
|
||||
|
@ -107,7 +107,7 @@ void bt_mesh_reset(void)
|
||||
|
||||
bt_mesh_cfg_reset();
|
||||
|
||||
bt_mesh_rx_reset();
|
||||
bt_mesh_rx_reset(true);
|
||||
bt_mesh_tx_reset();
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) {
|
||||
@ -459,18 +459,15 @@ int bt_mesh_deinit(struct bt_mesh_deinit_param *param)
|
||||
|
||||
bt_mesh_adv_deinit();
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
bt_mesh_settings_deinit(param->erase);
|
||||
}
|
||||
|
||||
err = bt_mesh_comp_deregister();
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
if (param->erase) {
|
||||
bt_mesh_clear_role();
|
||||
}
|
||||
bt_mesh_settings_deinit();
|
||||
}
|
||||
|
||||
bt_mesh_k_deinit();
|
||||
|
||||
return 0;
|
||||
|
@ -163,11 +163,11 @@ done:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_provisioner_deinit(bool erase)
|
||||
void bt_mesh_provisioner_release_netkey(bool erase)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < CONFIG_BLE_MESH_PROVISIONER_SUBNET_COUNT; i++) {
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh.p_sub); i++) {
|
||||
if (bt_mesh.p_sub[i]) {
|
||||
if (erase && IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
bt_mesh_clear_p_subnet(bt_mesh.p_sub[i]);
|
||||
@ -177,7 +177,18 @@ int bt_mesh_provisioner_deinit(bool erase)
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < CONFIG_BLE_MESH_PROVISIONER_APP_KEY_COUNT; i++) {
|
||||
if (erase && IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
bt_mesh_clear_p_net_idx();
|
||||
}
|
||||
bt_mesh.p_net_idx_next = 0U;
|
||||
return;
|
||||
}
|
||||
|
||||
void bt_mesh_provisioner_release_appkey(bool erase)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh.p_app_keys); i++) {
|
||||
if (bt_mesh.p_app_keys[i]) {
|
||||
if (erase && IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
bt_mesh_clear_p_app_key(bt_mesh.p_app_keys[i]);
|
||||
@ -187,22 +198,32 @@ int bt_mesh_provisioner_deinit(bool erase)
|
||||
}
|
||||
}
|
||||
|
||||
bt_mesh.p_net_idx_next = 0U;
|
||||
bt_mesh.p_app_idx_next = 0U;
|
||||
if (erase && IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
bt_mesh_clear_p_net_idx();
|
||||
bt_mesh_clear_p_app_idx();
|
||||
}
|
||||
bt_mesh.p_app_idx_next = 0U;
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < CONFIG_BLE_MESH_MAX_STORED_NODES; i++) {
|
||||
void bt_mesh_provisioner_release_node(bool erase)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(mesh_nodes); i++) {
|
||||
provisioner_remove_node(i, erase);
|
||||
}
|
||||
|
||||
all_node_count = 0U;
|
||||
prov_node_count = 0U;
|
||||
return;
|
||||
}
|
||||
|
||||
int bt_mesh_provisioner_deinit(bool erase)
|
||||
{
|
||||
bt_mesh_provisioner_release_netkey(erase);
|
||||
bt_mesh_provisioner_release_appkey(erase);
|
||||
bt_mesh_provisioner_release_node(erase);
|
||||
bt_mesh_provisioner_mutex_free();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,9 @@ int bt_mesh_provisioner_init(void);
|
||||
|
||||
int bt_mesh_provisioner_net_create(void);
|
||||
|
||||
void bt_mesh_provisioner_release_netkey(bool erase);
|
||||
void bt_mesh_provisioner_release_appkey(bool erase);
|
||||
void bt_mesh_provisioner_release_node(bool erase);
|
||||
int bt_mesh_provisioner_deinit(bool erase);
|
||||
|
||||
bool bt_mesh_provisioner_check_is_addr_dup(u16_t addr, u8_t elem_num, bool comp_with_own);
|
||||
|
@ -1126,6 +1126,11 @@ int bt_mesh_provisioner_set_prov_info(void)
|
||||
/* If unicast address of primary element of Provisioner has not been set
|
||||
* before, then the following initilization procedure will be used.
|
||||
*/
|
||||
if (prov == NULL) {
|
||||
BT_ERR("%s, NULL provisioning", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(prov->prov_unicast_addr) ||
|
||||
!BLE_MESH_ADDR_IS_UNICAST(prov->prov_start_address)) {
|
||||
BT_ERR("%s, Invalid address, own 0x%04x, start 0x%04x",
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -13,7 +13,7 @@
|
||||
int settings_core_init(void);
|
||||
int settings_core_load(void);
|
||||
int settings_core_commit(void);
|
||||
int settings_core_deinit(void);
|
||||
int settings_core_deinit(bool erase);
|
||||
|
||||
void bt_mesh_store_role(void);
|
||||
void bt_mesh_store_net(void);
|
||||
@ -29,6 +29,12 @@ void bt_mesh_store_cfg(void);
|
||||
void bt_mesh_store_mod_bind(struct bt_mesh_model *mod);
|
||||
void bt_mesh_store_mod_sub(struct bt_mesh_model *mod);
|
||||
void bt_mesh_store_mod_pub(struct bt_mesh_model *mod);
|
||||
void bt_mesh_clear_mod_bind(void);
|
||||
void bt_mesh_clear_mod_sub(void);
|
||||
void bt_mesh_clear_mod_pub(void);
|
||||
void bt_mesh_reset_mod_bind(void);
|
||||
void bt_mesh_reset_mod_sub(void);
|
||||
void bt_mesh_reset_mod_pub(void);
|
||||
void bt_mesh_store_label(void);
|
||||
|
||||
void bt_mesh_clear_role(void);
|
||||
@ -53,9 +59,31 @@ void bt_mesh_store_node_info(struct bt_mesh_node *node, bool prov);
|
||||
void bt_mesh_clear_node_info(u16_t unicast_addr, bool prov);
|
||||
void bt_mesh_store_node_name(struct bt_mesh_node *node, bool prov);
|
||||
void bt_mesh_store_node_comp_data(struct bt_mesh_node *node, bool prov);
|
||||
#endif
|
||||
#if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
int settings_user_id_init(void);
|
||||
int settings_user_id_load(void);
|
||||
int settings_user_id_deinit(bool erase);
|
||||
u32_t bt_mesh_provisioner_get_settings_handle(void);
|
||||
int bt_mesh_provisioner_open_settings_with_index(u8_t index);
|
||||
int bt_mesh_provisioner_open_settings_with_user_id(const char *user_id, u8_t *index);
|
||||
int bt_mesh_provisioner_close_settings_with_index(u8_t index);
|
||||
int bt_mesh_provisioner_close_settings_with_user_id(const char *user_id, u8_t *index);
|
||||
int bt_mesh_provisioner_restore_settings_with_index(u8_t index);
|
||||
int bt_mesh_provisioner_restore_settings_with_user_id(const char *user_id, u8_t *index);
|
||||
int bt_mesh_provisioner_release_settings_with_index(u8_t index, bool erase);
|
||||
int bt_mesh_provisioner_release_settings_with_user_id(const char *user_id, bool erase, u8_t *index);
|
||||
int bt_mesh_provisioner_delete_settings_with_index(u8_t index);
|
||||
int bt_mesh_provisioner_delete_settings_with_user_id(const char *user_id, u8_t *index);
|
||||
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 */
|
||||
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
||||
|
||||
void bt_mesh_settings_lock(void);
|
||||
void bt_mesh_settings_unlock(void);
|
||||
|
||||
int bt_mesh_settings_init(void);
|
||||
int bt_mesh_settings_deinit(void);
|
||||
int bt_mesh_settings_deinit(bool erase);
|
||||
|
||||
#endif /* _SETTINGS_H_ */
|
||||
|
@ -15,9 +15,6 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#include "mesh_common.h"
|
||||
#include "settings_nvs.h"
|
||||
#include "settings.h"
|
||||
@ -27,6 +24,9 @@
|
||||
enum settings_type {
|
||||
SETTINGS_CORE,
|
||||
SETTINGS_SERVER,
|
||||
#if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
SETTINGS_USER_ID,
|
||||
#endif
|
||||
};
|
||||
|
||||
struct settings_context {
|
||||
@ -36,8 +36,7 @@ struct settings_context {
|
||||
int (*settings_init)(void);
|
||||
int (*settings_load)(void);
|
||||
int (*settings_commit)(void);
|
||||
int (*settings_deinit)(void);
|
||||
int (*settings_erase)(void);
|
||||
int (*settings_deinit)(bool erase);
|
||||
};
|
||||
|
||||
static struct settings_context settings_ctx[] = {
|
||||
@ -54,12 +53,36 @@ static struct settings_context settings_ctx[] = {
|
||||
.settings_load = NULL,
|
||||
.settings_commit = NULL,
|
||||
},
|
||||
#if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
[SETTINGS_USER_ID] = {
|
||||
.nvs_name = "mesh_user_id",
|
||||
.settings_init = settings_user_id_init,
|
||||
.settings_load = settings_user_id_load,
|
||||
.settings_commit = NULL,
|
||||
.settings_deinit = settings_user_id_deinit,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
/* API used to initialize, load and commit BLE Mesh related settings */
|
||||
|
||||
int bt_mesh_settings_nvs_open(const char* name, nvs_handle *handle)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_SPECIFIC_PARTITION
|
||||
return nvs_open_from_partition(CONFIG_BLE_MESH_PARTITION_NAME, name, NVS_READWRITE, handle);
|
||||
#else
|
||||
return nvs_open(name, NVS_READWRITE, handle);
|
||||
#endif
|
||||
}
|
||||
|
||||
void bt_mesh_settings_nvs_close(nvs_handle handle)
|
||||
{
|
||||
nvs_close(handle);
|
||||
}
|
||||
|
||||
void bt_mesh_settings_foreach(void)
|
||||
{
|
||||
struct settings_context *ctx = NULL;
|
||||
int err = 0;
|
||||
int i;
|
||||
|
||||
@ -72,48 +95,67 @@ void bt_mesh_settings_foreach(void)
|
||||
#endif
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(settings_ctx); i++) {
|
||||
struct settings_context *ctx = &settings_ctx[i];
|
||||
|
||||
#if CONFIG_BLE_MESH_SPECIFIC_PARTITION
|
||||
err = nvs_open_from_partition(CONFIG_BLE_MESH_PARTITION_NAME, ctx->nvs_name, NVS_READWRITE, &ctx->handle);
|
||||
#else
|
||||
err = nvs_open(ctx->nvs_name, NVS_READWRITE, &ctx->handle);
|
||||
#endif
|
||||
if (err != ESP_OK) {
|
||||
BT_ERR("%s, Open nvs failed, name %s, err %d", __func__, ctx->nvs_name, err);
|
||||
continue;
|
||||
}
|
||||
ctx = &settings_ctx[i];
|
||||
|
||||
if (ctx->settings_init && ctx->settings_init()) {
|
||||
BT_ERR("%s, Init settings failed, name %s", __func__, ctx->nvs_name);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
/* If using multiple nvs namespaces, we will only restore user_id */
|
||||
ctx = &settings_ctx[SETTINGS_USER_ID];
|
||||
|
||||
err = bt_mesh_settings_nvs_open(ctx->nvs_name, &ctx->handle);
|
||||
if (err) {
|
||||
BT_ERR("%s, Open nvs failed, name %s, err %d", __func__, ctx->nvs_name, err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->settings_load && ctx->settings_load()) {
|
||||
BT_ERR("%s, Load settings failed, name %s", __func__, ctx->nvs_name);
|
||||
return;
|
||||
}
|
||||
#else /* CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE */
|
||||
/* If not using multiple nvs namespaces, we will follow the normal procedure,
|
||||
* i.e. restoring all the mesh information.
|
||||
*/
|
||||
for (i = 0; i < ARRAY_SIZE(settings_ctx); i++) {
|
||||
ctx = &settings_ctx[i];
|
||||
|
||||
err = bt_mesh_settings_nvs_open(ctx->nvs_name, &ctx->handle);
|
||||
if (err) {
|
||||
BT_ERR("%s, Open nvs failed, name %s, err %d", __func__, ctx->nvs_name, err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->settings_load && ctx->settings_load()) {
|
||||
BT_ERR("%s, Load settings failed, name %s", __func__, ctx->nvs_name);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->settings_commit && ctx->settings_commit()) {
|
||||
BT_ERR("%s, Commit settings failed, name %s", __func__, ctx->nvs_name);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE */
|
||||
}
|
||||
|
||||
void bt_mesh_settings_deforeach(void)
|
||||
void bt_mesh_settings_deforeach(bool erase)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(settings_ctx); i++) {
|
||||
struct settings_context *ctx = &settings_ctx[i];
|
||||
|
||||
if (ctx->settings_deinit && ctx->settings_deinit()) {
|
||||
if (ctx->settings_deinit && ctx->settings_deinit(erase)) {
|
||||
BT_ERR("%s, Deinit settings failed, name %s", __func__, ctx->nvs_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
nvs_close(ctx->handle);
|
||||
bt_mesh_settings_nvs_close(ctx->handle);
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_SPECIFIC_PARTITION
|
||||
@ -125,6 +167,11 @@ void bt_mesh_settings_deforeach(void)
|
||||
|
||||
static inline nvs_handle settings_get_nvs_handle(enum settings_type type)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
if (type == SETTINGS_CORE) {
|
||||
return bt_mesh_provisioner_get_settings_handle();
|
||||
}
|
||||
#endif
|
||||
return settings_ctx[type].handle;
|
||||
}
|
||||
|
||||
@ -165,12 +212,29 @@ static int settings_save(nvs_handle handle, const char *key, const u8_t *val, si
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_save_settings(nvs_handle handle, const char *key, const u8_t *val, size_t len)
|
||||
{
|
||||
int err = 0;
|
||||
bt_mesh_settings_lock();
|
||||
err = settings_save(handle, key, val, len);
|
||||
bt_mesh_settings_unlock();
|
||||
return err;
|
||||
}
|
||||
|
||||
int bt_mesh_save_core_settings(const char *key, const u8_t *val, size_t len)
|
||||
{
|
||||
nvs_handle handle = settings_get_nvs_handle(SETTINGS_CORE);
|
||||
return settings_save(handle, key, val, len);
|
||||
return bt_mesh_save_settings(handle, key, val, len);
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
int bt_mesh_save_user_id_settings(const char *key, const u8_t *val, size_t len)
|
||||
{
|
||||
nvs_handle handle = settings_get_nvs_handle(SETTINGS_USER_ID);
|
||||
return bt_mesh_save_settings(handle, key, val, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* API used to load BLE Mesh related settings */
|
||||
|
||||
static int settings_load(nvs_handle handle, const char *key,
|
||||
@ -199,12 +263,30 @@ static int settings_load(nvs_handle handle, const char *key,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_load_settings(nvs_handle handle, const char *key, u8_t *buf,
|
||||
size_t buf_len, bool *exist)
|
||||
{
|
||||
int err = 0;
|
||||
bt_mesh_settings_lock();
|
||||
err = settings_load(handle, key, buf, buf_len, exist);
|
||||
bt_mesh_settings_unlock();
|
||||
return err;
|
||||
}
|
||||
|
||||
int bt_mesh_load_core_settings(const char *key, u8_t *buf, size_t buf_len, bool *exist)
|
||||
{
|
||||
nvs_handle handle = settings_get_nvs_handle(SETTINGS_CORE);
|
||||
return settings_load(handle, key, buf, buf_len, exist);
|
||||
return bt_mesh_load_settings(handle, key, buf, buf_len, exist);
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
int bt_mesh_load_user_id_settings(const char *key, u8_t *buf, size_t buf_len, bool *exist)
|
||||
{
|
||||
nvs_handle handle = settings_get_nvs_handle(SETTINGS_USER_ID);
|
||||
return bt_mesh_load_settings(handle, key, buf, buf_len, exist);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* API used to get length of BLE Mesh related settings */
|
||||
|
||||
static size_t settings_get_length(nvs_handle handle, const char *key)
|
||||
@ -270,12 +352,29 @@ static struct net_buf_simple *settings_get_item(nvs_handle handle, const char *k
|
||||
return buf;
|
||||
}
|
||||
|
||||
struct net_buf_simple *bt_mesh_get_settings_item(nvs_handle handle, const char *key)
|
||||
{
|
||||
struct net_buf_simple *buf = NULL;
|
||||
bt_mesh_settings_lock();
|
||||
buf = settings_get_item(handle, key);
|
||||
bt_mesh_settings_unlock();
|
||||
return buf;
|
||||
}
|
||||
|
||||
struct net_buf_simple *bt_mesh_get_core_settings_item(const char *key)
|
||||
{
|
||||
nvs_handle handle = settings_get_nvs_handle(SETTINGS_CORE);
|
||||
return settings_get_item(handle, key);
|
||||
return bt_mesh_get_settings_item(handle, key);
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
struct net_buf_simple *bt_mesh_get_user_id_settings_item(const char *key)
|
||||
{
|
||||
nvs_handle handle = settings_get_nvs_handle(SETTINGS_USER_ID);
|
||||
return bt_mesh_get_settings_item(handle, key);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* API used to check if the settings item exists */
|
||||
|
||||
static bool is_settings_item_exist(struct net_buf_simple *buf, const u16_t val)
|
||||
@ -342,12 +441,29 @@ static int settings_add_item(nvs_handle handle, const char *key, const u16_t val
|
||||
return err;
|
||||
}
|
||||
|
||||
int bt_mesh_add_settings_item(nvs_handle handle, const char *key, const u16_t val)
|
||||
{
|
||||
int err = 0;
|
||||
bt_mesh_settings_lock();
|
||||
err = settings_add_item(handle, key, val);
|
||||
bt_mesh_settings_unlock();
|
||||
return err;
|
||||
}
|
||||
|
||||
int bt_mesh_add_core_settings_item(const char *key, const u16_t val)
|
||||
{
|
||||
nvs_handle handle = settings_get_nvs_handle(SETTINGS_CORE);
|
||||
return settings_add_item(handle, key, val);
|
||||
return bt_mesh_add_settings_item(handle, key, val);
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
int bt_mesh_add_user_id_settings_item(const char *key, const u16_t val)
|
||||
{
|
||||
nvs_handle handle = settings_get_nvs_handle(SETTINGS_USER_ID);
|
||||
return bt_mesh_add_settings_item(handle, key, val);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* API used to remove the settings item */
|
||||
|
||||
static int settings_remove_item(nvs_handle handle, const char *key, const u16_t val)
|
||||
@ -397,10 +513,27 @@ static int settings_remove_item(nvs_handle handle, const char *key, const u16_t
|
||||
return err;
|
||||
}
|
||||
|
||||
int bt_mesh_remove_settings_item(nvs_handle handle, const char *key, const u16_t val)
|
||||
{
|
||||
int err = 0;
|
||||
bt_mesh_settings_lock();
|
||||
err = settings_remove_item(handle, key, val);
|
||||
bt_mesh_settings_unlock();
|
||||
return err;
|
||||
}
|
||||
|
||||
int bt_mesh_remove_core_settings_item(const char *key, const u16_t val)
|
||||
{
|
||||
nvs_handle handle = settings_get_nvs_handle(SETTINGS_CORE);
|
||||
return settings_remove_item(handle, key, val);
|
||||
return bt_mesh_remove_settings_item(handle, key, val);
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
int bt_mesh_remove_user_id_settings_item(const char *key, const u16_t val)
|
||||
{
|
||||
nvs_handle handle = settings_get_nvs_handle(SETTINGS_USER_ID);
|
||||
return bt_mesh_remove_settings_item(handle, key, val);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_SETTINGS */
|
||||
|
@ -15,6 +15,8 @@
|
||||
#ifndef _BLE_MESH_SETTINGS_NVS_H_
|
||||
#define _BLE_MESH_SETTINGS_NVS_H_
|
||||
|
||||
#include "nvs.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "mesh_buf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -28,18 +30,29 @@ extern "C" {
|
||||
#define BLE_MESH_GET_MODEL_KEY(a, b) ((u16_t)(((u16_t)((a) << 8)) | b))
|
||||
|
||||
void bt_mesh_settings_foreach(void);
|
||||
void bt_mesh_settings_deforeach(void);
|
||||
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_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);
|
||||
int bt_mesh_add_settings_item(nvs_handle handle, const char *key, const u16_t val);
|
||||
int bt_mesh_remove_settings_item(nvs_handle handle, const char *key, const u16_t val);
|
||||
|
||||
int bt_mesh_save_core_settings(const char *key, const u8_t *val, size_t len);
|
||||
|
||||
int bt_mesh_load_core_settings(const char *key, u8_t *buf, size_t buf_len, bool *exist);
|
||||
|
||||
struct net_buf_simple *bt_mesh_get_core_settings_item(const char *key);
|
||||
|
||||
int bt_mesh_add_core_settings_item(const char *key, const u16_t val);
|
||||
|
||||
int bt_mesh_remove_core_settings_item(const char *key, const u16_t val);
|
||||
|
||||
int bt_mesh_save_user_id_settings(const char *key, const u8_t *val, size_t len);
|
||||
int bt_mesh_load_user_id_settings(const char *key, u8_t *buf, size_t buf_len, bool *exist);
|
||||
struct net_buf_simple *bt_mesh_get_user_id_settings_item(const char *key);
|
||||
int bt_mesh_add_user_id_settings_item(const char *key, const u16_t val);
|
||||
int bt_mesh_remove_user_id_settings_item(const char *key, const u16_t val);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1556,7 +1556,7 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx)
|
||||
return err;
|
||||
}
|
||||
|
||||
void bt_mesh_rx_reset(void)
|
||||
void bt_mesh_rx_reset(bool erase)
|
||||
{
|
||||
int i;
|
||||
|
||||
@ -1566,7 +1566,11 @@ void bt_mesh_rx_reset(void)
|
||||
seg_rx_reset(&seg_rx[i], true);
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
/* For node, the "erase" flag shall always be true. And
|
||||
* only the macro CONFIG_BLE_MESH_SETTINGS will be used
|
||||
* to decide whether to erase the RPL list from flash.
|
||||
*/
|
||||
if (erase && IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||
bt_mesh_clear_rpl();
|
||||
} else {
|
||||
(void)memset(bt_mesh.rpl, 0, sizeof(bt_mesh.rpl));
|
||||
|
@ -86,7 +86,7 @@ struct bt_mesh_app_key *bt_mesh_app_key_find(u16_t app_idx);
|
||||
|
||||
bool bt_mesh_tx_in_progress(void);
|
||||
|
||||
void bt_mesh_rx_reset(void);
|
||||
void bt_mesh_rx_reset(bool erase);
|
||||
void bt_mesh_tx_reset(void);
|
||||
|
||||
int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data,
|
||||
|
Loading…
x
Reference in New Issue
Block a user