[PATCH BlueZ] mesh: Update AppKeys on transition to Phase 0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

---
 mesh/appkey.c | 18 ++++++++++++++++++
 mesh/appkey.h |  1 +
 mesh/net.c    |  2 ++
 3 files changed, 21 insertions(+)

diff --git a/mesh/appkey.c b/mesh/appkey.c
index 549f5a80d..504f67aab 100644
--- a/mesh/appkey.c
+++ b/mesh/appkey.c
@@ -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);
diff --git a/mesh/appkey.h b/mesh/appkey.h
index 3bb70445b..c83dd03f6 100644
--- a/mesh/appkey.h
+++ b/mesh/appkey.h
@@ -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,
diff --git a/mesh/net.c b/mesh/net.c
index b24cdba77..22ec03d7a 100644
--- a/mesh/net.c
+++ b/mesh/net.c
@@ -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;
-- 
2.26.2




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux