summaryrefslogtreecommitdiff
path: root/mesh/appkey.c
diff options
context:
space:
mode:
authorMichael N. Moran <mike@mnmoran.org>2021-01-03 22:48:37 -0500
committerBrian Gix <brian.gix@intel.com>2021-01-04 08:58:37 -0800
commit6bbbabfe883f6d6b59ee0db76bf2f30fae971f39 (patch)
tree2d3d46d280df411263f148bcb12fd8d09784225f /mesh/appkey.c
parent8b9ec615b3e174b02ff2df93e1980a786e7611a3 (diff)
downloadbluez-6bbbabfe883f6d6b59ee0db76bf2f30fae971f39.tar.gz
mesh: Update AppKeys on transition to Phase 0
At the end of the mesh Key Refresh procedure when a subnet transitions to Phase 0, local AppKeys that were updated were not updating until the bluetooth-meshd daemon was restarted. This patch iterates the AppKeys at the end of mesh Key Refresh when the subnet transitions to Phase 0, setting the new state of each updated AppKey.
Diffstat (limited to 'mesh/appkey.c')
-rw-r--r--mesh/appkey.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/mesh/appkey.c b/mesh/appkey.c
index 549f5a80d..5088a1812 100644
--- a/mesh/appkey.c
+++ b/mesh/appkey.c
@@ -50,11 +50,40 @@ static bool match_bound_key(const void *a, const void *b)
return key->net_idx == idx;
}
+static void finalize_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 == APP_AID_INVALID)
+ return;
+
+ key->key_aid = key->new_key_aid;
+
+ key->new_key_aid = APP_AID_INVALID;
+
+ memcpy(key->key, key->new_key, 16);
+}
+
+void appkey_finalize(struct mesh_net *net, uint16_t net_idx)
+{
+ struct l_queue *app_keys;
+
+ app_keys = mesh_net_get_app_keys(net);
+ if (!app_keys)
+ return;
+
+ l_queue_foreach(app_keys, finalize_key, L_UINT_TO_PTR(net_idx));
+}
+
static struct mesh_app_key *app_key_new(void)
{
struct mesh_app_key *key = l_new(struct mesh_app_key, 1);
- key->new_key_aid = 0xFF;
+ key->new_key_aid = APP_AID_INVALID;
return key;
}
@@ -146,7 +175,7 @@ const uint8_t *appkey_get_key(struct mesh_net *net, uint16_t app_idx,
return app_key->key;
}
- if (app_key->new_key_aid == NET_NID_INVALID)
+ if (app_key->new_key_aid == APP_AID_INVALID)
return NULL;
*key_aid = app_key->new_key_aid;