@@ -50,6 +50,24 @@ static bool match_bound_key(const void *a, const void *b)
return key->net_idx == idx;
}
+void finish_app_key(void *a, void *b)
+{
+ struct mesh_app_key *key = a;
+ uint16_t net_idx = L_PTR_TO_UINT(b);
+
+ if (key->net_idx != net_idx)
+ return;
+
+ if (key->new_key_aid == NET_NID_INVALID)
+ return;
+
+ key->key_aid = key->new_key_aid;
+
+ key->new_key_aid = NET_NID_INVALID;
+
+ memcpy(key->key, key->new_key, 16);
+}
+
static struct mesh_app_key *app_key_new(void)
{
struct mesh_app_key *key = l_new(struct mesh_app_key, 1);
@@ -16,6 +16,7 @@ struct mesh_app_key;
bool appkey_key_init(struct mesh_net *net, uint16_t net_idx, uint16_t app_idx,
uint8_t *key_value, uint8_t *new_key_value);
void appkey_key_free(void *data);
+void finish_app_key(void *a, void *b);
const uint8_t *appkey_get_key(struct mesh_net *net, uint16_t app_idx,
uint8_t *key_id);
int appkey_get_key_idx(struct mesh_app_key *app_key,
@@ -2600,6 +2600,8 @@ static int key_refresh_finish(struct mesh_net *net, uint16_t idx)
l_queue_foreach(net->friends, frnd_kr_phase3, net);
+ l_queue_foreach(net->app_keys, finish_app_key, L_UINT_TO_PTR(idx));
+
if (!mesh_config_net_key_set_phase(node_config_get(net->node), idx,
KEY_REFRESH_PHASE_NONE))
return MESH_STATUS_STORAGE_FAIL;