All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ v2] mesh: Update AppKeys on transition to Phase 0
@ 2021-01-04  3:48 Michael N. Moran
  2021-01-04  4:17 ` [BlueZ,v2] " bluez.test.bot
  2021-01-04 16:59 ` [PATCH BlueZ v2] " Gix, Brian
  0 siblings, 2 replies; 3+ messages in thread
From: Michael N. Moran @ 2021-01-04  3:48 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, inga.stotland, Michael N. Moran

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.

********* v2 ************

This version incorporates recommendations from Brian Gix
creating a public function appkey_finalize(); and adding
new APP_AID_INVALID constant to replace the use of 0xFF
as an indication that the new_key_aid field is invalid.


---
 mesh/appkey.c    | 33 +++++++++++++++++++++++++++++++--
 mesh/appkey.h    |  1 +
 mesh/mesh-defs.h |  1 +
 mesh/net.c       |  2 ++
 4 files changed, 35 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;
diff --git a/mesh/appkey.h b/mesh/appkey.h
index 3bb70445b..6688d87fb 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 appkey_finalize(struct mesh_net *net, uint16_t net_idx);
 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/mesh-defs.h b/mesh/mesh-defs.h
index 43bdf5aab..25ce0126c 100644
--- a/mesh/mesh-defs.h
+++ b/mesh/mesh-defs.h
@@ -100,6 +100,7 @@
 
 #define NET_IDX_MAX		0x0fff
 #define APP_IDX_MAX		0x0fff
+#define APP_AID_INVALID	0xff
 
 #define APP_IDX_MASK		0x0fff
 #define APP_IDX_DEV_REMOTE	0x6fff
diff --git a/mesh/net.c b/mesh/net.c
index b24cdba77..9624cd058 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);
 
+	appkey_finalize(net, 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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [BlueZ,v2] mesh: Update AppKeys on transition to Phase 0
  2021-01-04  3:48 [PATCH BlueZ v2] mesh: Update AppKeys on transition to Phase 0 Michael N. Moran
@ 2021-01-04  4:17 ` bluez.test.bot
  2021-01-04 16:59 ` [PATCH BlueZ v2] " Gix, Brian
  1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2021-01-04  4:17 UTC (permalink / raw)
  To: linux-bluetooth, mike

[-- Attachment #1: Type: text/plain, Size: 557 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=408415

---Test result---

##############################
Test: CheckPatch - PASS

##############################
Test: CheckGitLint - PASS

##############################
Test: CheckBuild - PASS

##############################
Test: MakeCheck - PASS



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH BlueZ v2] mesh: Update AppKeys on transition to Phase 0
  2021-01-04  3:48 [PATCH BlueZ v2] mesh: Update AppKeys on transition to Phase 0 Michael N. Moran
  2021-01-04  4:17 ` [BlueZ,v2] " bluez.test.bot
@ 2021-01-04 16:59 ` Gix, Brian
  1 sibling, 0 replies; 3+ messages in thread
From: Gix, Brian @ 2021-01-04 16:59 UTC (permalink / raw)
  To: mike, linux-bluetooth; +Cc: Stotland, Inga

Applied, Thanks

On Sun, 2021-01-03 at 22:48 -0500, Michael N. Moran wrote:
> 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.
> 
> ********* v2 ************
> 
> This version incorporates recommendations from Brian Gix
> creating a public function appkey_finalize(); and adding
> new APP_AID_INVALID constant to replace the use of 0xFF
> as an indication that the new_key_aid field is invalid.
> 
> 
> ---
>  mesh/appkey.c    | 33 +++++++++++++++++++++++++++++++--
>  mesh/appkey.h    |  1 +
>  mesh/mesh-defs.h |  1 +
>  mesh/net.c       |  2 ++
>  4 files changed, 35 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;
> diff --git a/mesh/appkey.h b/mesh/appkey.h
> index 3bb70445b..6688d87fb 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 appkey_finalize(struct mesh_net *net, uint16_t net_idx);
>  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/mesh-defs.h b/mesh/mesh-defs.h
> index 43bdf5aab..25ce0126c 100644
> --- a/mesh/mesh-defs.h
> +++ b/mesh/mesh-defs.h
> @@ -100,6 +100,7 @@
>  
>  #define NET_IDX_MAX		0x0fff
>  #define APP_IDX_MAX		0x0fff
> +#define APP_AID_INVALID	0xff
>  
>  #define APP_IDX_MASK		0x0fff
>  #define APP_IDX_DEV_REMOTE	0x6fff
> diff --git a/mesh/net.c b/mesh/net.c
> index b24cdba77..9624cd058 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);
>  
> +	appkey_finalize(net, idx);
> +
>  	if (!mesh_config_net_key_set_phase(node_config_get(net->node), idx,
>  							KEY_REFRESH_PHASE_NONE))
>  		return MESH_STATUS_STORAGE_FAIL;

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-04 17:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-04  3:48 [PATCH BlueZ v2] mesh: Update AppKeys on transition to Phase 0 Michael N. Moran
2021-01-04  4:17 ` [BlueZ,v2] " bluez.test.bot
2021-01-04 16:59 ` [PATCH BlueZ v2] " Gix, Brian

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.