ble_mesh: stack: Erase netkey and appkey with key index

This commit is contained in:
lly 2020-05-27 09:42:50 +08:00
parent d51431fff5
commit de15e502a7
3 changed files with 30 additions and 50 deletions

View file

@ -165,7 +165,7 @@ int bt_mesh_provisioner_deinit(bool erase)
for (i = 0; i < CONFIG_BLE_MESH_PROVISIONER_SUBNET_COUNT; 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]);
bt_mesh_clear_p_subnet(bt_mesh.p_sub[i]->net_idx);
}
bt_mesh_free(bt_mesh.p_sub[i]);
bt_mesh.p_sub[i] = NULL;
@ -175,7 +175,7 @@ int bt_mesh_provisioner_deinit(bool erase)
for (i = 0; i < CONFIG_BLE_MESH_PROVISIONER_APP_KEY_COUNT; 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]);
bt_mesh_clear_p_app_key(bt_mesh.p_app_keys[i]->app_idx);
}
bt_mesh_free(bt_mesh.p_app_keys[i]);
bt_mesh.p_app_keys[i] = NULL;
@ -1198,7 +1198,7 @@ int bt_mesh_provisioner_local_app_key_delete(u16_t net_idx, u16_t app_idx)
bt_mesh_model_foreach(_model_unbind, &app_idx);
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
bt_mesh_clear_p_app_key(key);
bt_mesh_clear_p_app_key(app_idx);
}
bt_mesh_free(bt_mesh.p_app_keys[i]);
@ -1391,7 +1391,7 @@ int bt_mesh_provisioner_local_net_key_delete(u16_t net_idx)
}
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
bt_mesh_clear_p_subnet(sub);
bt_mesh_clear_p_subnet(net_idx);
}
bt_mesh_free(bt_mesh.p_sub[i]);

View file

@ -2302,34 +2302,6 @@ void bt_mesh_clear_prov_info(void)
bt_mesh_erase_core_settings("mesh/p_prov");
}
static void clear_p_net_key(u16_t net_idx)
{
char name[16] = {'\0'};
int err = 0;
sprintf(name, "mesh/pnk/%04x", net_idx);
bt_mesh_erase_core_settings(name);
err = bt_mesh_remove_core_settings_item("mesh/p_netkey", net_idx);
if (err) {
BT_ERR("Failed to remove 0x%03x from mesh/p_netkey", net_idx);
}
}
static void clear_p_app_key(u16_t app_idx)
{
char name[16] = {'\0'};
int err = 0;
sprintf(name, "mesh/pak/%04x", app_idx);
bt_mesh_erase_core_settings(name);
err = bt_mesh_remove_core_settings_item("mesh/p_appkey", app_idx);
if (err) {
BT_ERR("Failed to remove 0x%03x from mesh/p_appkey", app_idx);
}
}
static void store_p_net_key(struct bt_mesh_subnet *sub)
{
struct net_key_val key = {0};
@ -2432,28 +2404,36 @@ void bt_mesh_store_p_app_key(struct bt_mesh_app_key *key)
store_p_app_key(key);
}
void bt_mesh_clear_p_subnet(struct bt_mesh_subnet *sub)
void bt_mesh_clear_p_subnet(u16_t net_idx)
{
if (sub == NULL) {
BT_ERR("Invalid subnet");
return;
char name[16] = {'\0'};
int err = 0;
BT_DBG("NetKeyIndex 0x%03x", net_idx);
sprintf(name, "mesh/pnk/%04x", net_idx);
bt_mesh_erase_core_settings(name);
err = bt_mesh_remove_core_settings_item("mesh/p_netkey", net_idx);
if (err) {
BT_ERR("Failed to remove 0x%04x from mesh/p_netkey", net_idx);
}
BT_DBG("NetKeyIndex 0x%03x", sub->net_idx);
clear_p_net_key(sub->net_idx);
}
void bt_mesh_clear_p_app_key(struct bt_mesh_app_key *key)
void bt_mesh_clear_p_app_key(u16_t app_idx)
{
if (key == NULL) {
BT_ERR("Invalid AppKey");
return;
char name[16] = {'\0'};
int err = 0;
BT_DBG("AppKeyIndex 0x%03x", app_idx);
sprintf(name, "mesh/pak/%04x", app_idx);
bt_mesh_erase_core_settings(name);
err = bt_mesh_remove_core_settings_item("mesh/p_appkey", app_idx);
if (err) {
BT_ERR("Failed to remove 0x%04x from mesh/p_appkey", app_idx);
}
BT_DBG("AppKeyIndex 0x%03x", key->app_idx);
clear_p_app_key(key->app_idx);
}
void bt_mesh_clear_rpl_single(u16_t src)

View file

@ -55,8 +55,8 @@ void bt_mesh_store_p_app_idx(void);
void bt_mesh_clear_p_app_idx(void);
void bt_mesh_store_p_subnet(struct bt_mesh_subnet *sub);
void bt_mesh_store_p_app_key(struct bt_mesh_app_key *key);
void bt_mesh_clear_p_subnet(struct bt_mesh_subnet *sub);
void bt_mesh_clear_p_app_key(struct bt_mesh_app_key *key);
void bt_mesh_clear_p_subnet(u16_t net_idx);
void bt_mesh_clear_p_app_key(u16_t app_idx);
void bt_mesh_clear_rpl_single(u16_t src);
void bt_mesh_store_node_info(struct bt_mesh_node *node);
void bt_mesh_clear_node_info(u16_t unicast_addr);