All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 0/4] Allow some composition fields update
@ 2020-05-09  0:00 Inga Stotland
  2020-05-09  0:00 ` [PATCH BlueZ 1/4] mesh: On node attach, verify element/model composition only Inga Stotland
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Inga Stotland @ 2020-05-09  0:00 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, Inga Stotland

This patchset modifies how we verify the integrity of an existing
node when processing Attach() call.

The changes:
- Vericifaction includes only element/models relationship: this should
  stay constant during node's lifetime.
- Allow updating of CID, PID, VID and CRPL.
- Some general cleanup related to saving node configuration.

Inga Stotland (4):
  mesh: On node attach, verify element/model composition only
  mesh: Avoid saving duplicate fields in node config
  mesh: Allow updating CID, PID, VID & CRPL on node attach
  mesh: Remove redundant call to save node configuration

 mesh/mesh-config-json.c | 56 +++++++++++++++++++++++++++++++++--------
 mesh/mesh-config.h      |  4 +++
 mesh/node.c             | 29 +++++++++++++++------
 3 files changed, 71 insertions(+), 18 deletions(-)

-- 
2.21.3


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

* [PATCH BlueZ 1/4] mesh: On node attach, verify element/model composition only
  2020-05-09  0:00 [PATCH BlueZ 0/4] Allow some composition fields update Inga Stotland
@ 2020-05-09  0:00 ` Inga Stotland
  2020-05-09 13:49   ` Gix, Brian
  2020-05-14 17:05   ` Gix, Brian
  2020-05-09  0:00 ` [PATCH BlueZ 2/4] mesh: Avoid saving duplicate fields in node config Inga Stotland
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 7+ messages in thread
From: Inga Stotland @ 2020-05-09  0:00 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, Inga Stotland

When attaching an existing node, verify only the "elements" part
of device composition, i.e., skip verification of CID/PID/VID, CRPL
and features.
---
 mesh/node.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/mesh/node.c b/mesh/node.c
index acda6d472..e3f9e52e3 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -1378,7 +1378,7 @@ static bool check_req_node(struct managed_obj_request *req)
 {
 	uint8_t node_comp[MAX_MSG_LEN - 2];
 	uint8_t attach_comp[MAX_MSG_LEN - 2];
-
+	uint16_t offset = 10;
 	uint16_t node_len = node_generate_comp(req->node, node_comp,
 							sizeof(node_comp));
 
@@ -1389,12 +1389,10 @@ static bool check_req_node(struct managed_obj_request *req)
 		uint16_t attach_len = node_generate_comp(req->attach,
 					attach_comp, sizeof(attach_comp));
 
-		/* Ignore feature bits in Composition Compare */
-		node_comp[8] = 0;
-		attach_comp[8] = 0;
-
+		/* Verify only element/models composition */
 		if (node_len != attach_len ||
-				memcmp(node_comp, attach_comp, node_len)) {
+				memcmp(&node_comp[offset], &attach_comp[offset],
+							node_len - offset)) {
 			l_debug("Failed to verify app's composition data");
 			return false;
 		}
-- 
2.21.3


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

* [PATCH BlueZ 2/4] mesh: Avoid saving duplicate fields in node config
  2020-05-09  0:00 [PATCH BlueZ 0/4] Allow some composition fields update Inga Stotland
  2020-05-09  0:00 ` [PATCH BlueZ 1/4] mesh: On node attach, verify element/model composition only Inga Stotland
@ 2020-05-09  0:00 ` Inga Stotland
  2020-05-09  0:00 ` [PATCH BlueZ 3/4] mesh: Allow updating CID, PID, VID & CRPL on node attach Inga Stotland
  2020-05-09  0:00 ` [PATCH BlueZ 4/4] mesh: Remove redundant call to save node configuration Inga Stotland
  3 siblings, 0 replies; 7+ messages in thread
From: Inga Stotland @ 2020-05-09  0:00 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, Inga Stotland

This modifies miscellaneous utility functions in mesh-config-json.c:
when writing a new value to a node configuration file, delete
the existing field containing an old value first.
---
 mesh/mesh-config-json.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index 7362112f2..ce7058b5a 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
@@ -105,7 +105,7 @@ static bool get_int(json_object *jobj, const char *keyword, int *value)
 	return true;
 }
 
-static bool add_u64_value(json_object *jobject, const char *desc,
+static bool add_u64_value(json_object *jobj, const char *desc,
 					const uint8_t u64[8])
 {
 	json_object *jstring;
@@ -116,11 +116,12 @@ static bool add_u64_value(json_object *jobject, const char *desc,
 	if (!jstring)
 		return false;
 
-	json_object_object_add(jobject, desc, jstring);
+	json_object_object_del(jobj, desc);
+	json_object_object_add(jobj, desc, jstring);
 	return true;
 }
 
-static bool add_key_value(json_object *jobject, const char *desc,
+static bool add_key_value(json_object *jobj, const char *desc,
 					const uint8_t key[16])
 {
 	json_object *jstring;
@@ -131,7 +132,8 @@ static bool add_key_value(json_object *jobject, const char *desc,
 	if (!jstring)
 		return false;
 
-	json_object_object_add(jobject, desc, jstring);
+	json_object_object_del(jobj, desc);
+	json_object_object_add(jobj, desc, jstring);
 	return true;
 }
 
@@ -1398,6 +1400,7 @@ static bool write_uint16_hex(json_object *jobj, const char *desc,
 	if (!jstring)
 		return false;
 
+	json_object_object_del(jobj, desc);
 	json_object_object_add(jobj, desc, jstring);
 	return true;
 }
@@ -1412,21 +1415,21 @@ static bool write_uint32_hex(json_object *jobj, const char *desc, uint32_t val)
 	if (!jstring)
 		return false;
 
+	json_object_object_del(jobj, desc);
 	json_object_object_add(jobj, desc, jstring);
 	return true;
 }
 
-static bool write_int(json_object *jobj, const char *keyword, int val)
+static bool write_int(json_object *jobj, const char *desc, int val)
 {
 	json_object *jvalue;
 
-	json_object_object_del(jobj, keyword);
-
 	jvalue = json_object_new_int(val);
 	if (!jvalue)
 		return false;
 
-	json_object_object_add(jobj, keyword, jvalue);
+	json_object_object_del(jobj, desc);
+	json_object_object_add(jobj, desc, jvalue);
 	return true;
 }
 
@@ -1442,7 +1445,7 @@ static const char *mode_to_string(int mode)
 	}
 }
 
-static bool write_mode(json_object *jobj, const char *keyword, int value)
+static bool write_mode(json_object *jobj, const char *desc, int value)
 {
 	json_object *jstring;
 
@@ -1451,7 +1454,8 @@ static bool write_mode(json_object *jobj, const char *keyword, int value)
 	if (!jstring)
 		return false;
 
-	json_object_object_add(jobj, keyword, jstring);
+	json_object_object_del(jobj, desc);
+	json_object_object_add(jobj, desc, jstring);
 
 	return true;
 }
-- 
2.21.3


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

* [PATCH BlueZ 3/4] mesh: Allow updating CID, PID, VID & CRPL on node attach
  2020-05-09  0:00 [PATCH BlueZ 0/4] Allow some composition fields update Inga Stotland
  2020-05-09  0:00 ` [PATCH BlueZ 1/4] mesh: On node attach, verify element/model composition only Inga Stotland
  2020-05-09  0:00 ` [PATCH BlueZ 2/4] mesh: Avoid saving duplicate fields in node config Inga Stotland
@ 2020-05-09  0:00 ` Inga Stotland
  2020-05-09  0:00 ` [PATCH BlueZ 4/4] mesh: Remove redundant call to save node configuration Inga Stotland
  3 siblings, 0 replies; 7+ messages in thread
From: Inga Stotland @ 2020-05-09  0:00 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, Inga Stotland

This allows to update settings of the following composition fields
when an existing node (application) attaches to the daemon:
Company ID (CID), Product ID (PID), Versioin ID (VID),
CRPL (replay protection depth)
---
 mesh/mesh-config-json.c | 32 ++++++++++++++++++++++++++++++++
 mesh/mesh-config.h      |  4 ++++
 mesh/node.c             | 17 +++++++++++++++++
 3 files changed, 53 insertions(+)

diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index ce7058b5a..9ac3979f8 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
@@ -2057,6 +2057,38 @@ bool mesh_config_write_ttl(struct mesh_config *cfg, uint8_t ttl)
 	return save_config(cfg->jnode, cfg->node_dir_path);
 }
 
+bool mesh_config_update_company_id(struct mesh_config *cfg, uint16_t cid)
+{
+	if (!cfg || !write_uint16_hex(cfg->jnode, "cid", cid))
+		return false;
+
+	return save_config(cfg->jnode, cfg->node_dir_path);
+}
+
+bool mesh_config_update_product_id(struct mesh_config *cfg, uint16_t pid)
+{
+	if (!cfg || !write_uint16_hex(cfg->jnode, "pid", pid))
+		return false;
+
+	return save_config(cfg->jnode, cfg->node_dir_path);
+}
+
+bool mesh_config_update_version_id(struct mesh_config *cfg, uint16_t vid)
+{
+	if (!cfg || !write_uint16_hex(cfg->jnode, "vid", vid))
+		return false;
+
+	return save_config(cfg->jnode, cfg->node_dir_path);
+}
+
+bool mesh_config_update_crpl(struct mesh_config *cfg, uint16_t crpl)
+{
+	if (!cfg || !write_uint16_hex(cfg->jnode, "crpl", crpl))
+		return false;
+
+	return save_config(cfg->jnode, cfg->node_dir_path);
+}
+
 static bool load_node(const char *fname, const uint8_t uuid[16],
 				mesh_config_node_func_t cb, void *user_data)
 {
diff --git a/mesh/mesh-config.h b/mesh/mesh-config.h
index a5b12bbad..25002f5a7 100644
--- a/mesh/mesh-config.h
+++ b/mesh/mesh-config.h
@@ -172,3 +172,7 @@ bool mesh_config_net_key_set_phase(struct mesh_config *cfg, uint16_t idx,
 bool mesh_config_write_address(struct mesh_config *cfg, uint16_t address);
 bool mesh_config_write_iv_index(struct mesh_config *cfg, uint32_t idx,
 								bool update);
+bool mesh_config_update_company_id(struct mesh_config *cfg, uint16_t cid);
+bool mesh_config_update_product_id(struct mesh_config *cfg, uint16_t pid);
+bool mesh_config_update_version_id(struct mesh_config *cfg, uint16_t vid);
+bool mesh_config_update_crpl(struct mesh_config *cfg, uint16_t crpl);
diff --git a/mesh/node.c b/mesh/node.c
index e3f9e52e3..a96c0cae1 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -1374,6 +1374,21 @@ static bool add_local_node(struct mesh_node *node, uint16_t unicast, bool kr,
 	return true;
 }
 
+static void update_composition(struct mesh_node *node, struct mesh_node *attach)
+{
+	if (node->comp.cid != attach->comp.cid)
+		mesh_config_update_company_id(node->cfg, attach->comp.cid);
+
+	if (node->comp.pid != attach->comp.pid)
+		mesh_config_update_product_id(node->cfg, attach->comp.pid);
+
+	if (node->comp.vid != attach->comp.vid)
+		mesh_config_update_version_id(node->cfg, attach->comp.vid);
+
+	if (node->comp.crpl != attach->comp.crpl)
+		mesh_config_update_crpl(node->cfg, attach->comp.crpl);
+}
+
 static bool check_req_node(struct managed_obj_request *req)
 {
 	uint8_t node_comp[MAX_MSG_LEN - 2];
@@ -1444,6 +1459,8 @@ static bool attach_req_node(struct mesh_node *attach, struct mesh_node *node)
 	attach->owner = node->owner;
 	node->owner = NULL;
 
+	update_composition(node, attach);
+
 	node_remove(node);
 
 	return true;
-- 
2.21.3


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

* [PATCH BlueZ 4/4] mesh: Remove redundant call to save node configuration
  2020-05-09  0:00 [PATCH BlueZ 0/4] Allow some composition fields update Inga Stotland
                   ` (2 preceding siblings ...)
  2020-05-09  0:00 ` [PATCH BlueZ 3/4] mesh: Allow updating CID, PID, VID & CRPL on node attach Inga Stotland
@ 2020-05-09  0:00 ` Inga Stotland
  3 siblings, 0 replies; 7+ messages in thread
From: Inga Stotland @ 2020-05-09  0:00 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: brian.gix, Inga Stotland

This removes a redundant call to save node configuration in
add_local_node(): there is a number of unconditional calls to
mesh_config_write_<some_node_Setting>() within this function
which would result in the node configuration being saved implicitly.
---
 mesh/node.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/mesh/node.c b/mesh/node.c
index a96c0cae1..8914b639d 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -1366,8 +1366,6 @@ static bool add_local_node(struct mesh_node *node, uint16_t unicast, bool kr,
 
 	update_net_settings(node);
 
-	mesh_config_save(node->cfg, true, NULL, NULL);
-
 	/* Initialize configuration server model */
 	cfgmod_server_init(node, PRIMARY_ELE_IDX);
 
-- 
2.21.3


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

* Re: [PATCH BlueZ 1/4] mesh: On node attach, verify element/model composition only
  2020-05-09  0:00 ` [PATCH BlueZ 1/4] mesh: On node attach, verify element/model composition only Inga Stotland
@ 2020-05-09 13:49   ` Gix, Brian
  2020-05-14 17:05   ` Gix, Brian
  1 sibling, 0 replies; 7+ messages in thread
From: Gix, Brian @ 2020-05-09 13:49 UTC (permalink / raw)
  To: linux-bluetooth, Stotland, Inga

Applying this patch of the set early, due to popular demand.

On Fri, 2020-05-08 at 17:00 -0700, Inga Stotland wrote:
> When attaching an existing node, verify only the "elements" part
> of device composition, i.e., skip verification of CID/PID/VID, CRPL
> and features.
> ---
>  mesh/node.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/mesh/node.c b/mesh/node.c
> index acda6d472..e3f9e52e3 100644
> --- a/mesh/node.c
> +++ b/mesh/node.c
> @@ -1378,7 +1378,7 @@ static bool check_req_node(struct managed_obj_request *req)
>  {
>  	uint8_t node_comp[MAX_MSG_LEN - 2];
>  	uint8_t attach_comp[MAX_MSG_LEN - 2];
> -
> +	uint16_t offset = 10;
>  	uint16_t node_len = node_generate_comp(req->node, node_comp,
>  							sizeof(node_comp));
>  
> @@ -1389,12 +1389,10 @@ static bool check_req_node(struct managed_obj_request *req)
>  		uint16_t attach_len = node_generate_comp(req->attach,
>  					attach_comp, sizeof(attach_comp));
>  
> -		/* Ignore feature bits in Composition Compare */
> -		node_comp[8] = 0;
> -		attach_comp[8] = 0;
> -
> +		/* Verify only element/models composition */
>  		if (node_len != attach_len ||
> -				memcmp(node_comp, attach_comp, node_len)) {
> +				memcmp(&node_comp[offset], &attach_comp[offset],
> +							node_len - offset)) {
>  			l_debug("Failed to verify app's composition data");
>  			return false;
>  		}

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

* Re: [PATCH BlueZ 1/4] mesh: On node attach, verify element/model composition only
  2020-05-09  0:00 ` [PATCH BlueZ 1/4] mesh: On node attach, verify element/model composition only Inga Stotland
  2020-05-09 13:49   ` Gix, Brian
@ 2020-05-14 17:05   ` Gix, Brian
  1 sibling, 0 replies; 7+ messages in thread
From: Gix, Brian @ 2020-05-14 17:05 UTC (permalink / raw)
  To: linux-bluetooth, Stotland, Inga; +Cc: michal.lowas-rzechonek

full Patchset Applied

On Fri, 2020-05-08 at 17:00 -0700, Inga Stotland wrote:
> When attaching an existing node, verify only the "elements" part
> of device composition, i.e., skip verification of CID/PID/VID, CRPL
> and features.
> ---
>  mesh/node.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/mesh/node.c b/mesh/node.c
> index acda6d472..e3f9e52e3 100644
> --- a/mesh/node.c
> +++ b/mesh/node.c
> @@ -1378,7 +1378,7 @@ static bool check_req_node(struct managed_obj_request *req)
>  {
>  	uint8_t node_comp[MAX_MSG_LEN - 2];
>  	uint8_t attach_comp[MAX_MSG_LEN - 2];
> -
> +	uint16_t offset = 10;
>  	uint16_t node_len = node_generate_comp(req->node, node_comp,
>  							sizeof(node_comp));
>  
> @@ -1389,12 +1389,10 @@ static bool check_req_node(struct managed_obj_request *req)
>  		uint16_t attach_len = node_generate_comp(req->attach,
>  					attach_comp, sizeof(attach_comp));
>  
> -		/* Ignore feature bits in Composition Compare */
> -		node_comp[8] = 0;
> -		attach_comp[8] = 0;
> -
> +		/* Verify only element/models composition */
>  		if (node_len != attach_len ||
> -				memcmp(node_comp, attach_comp, node_len)) {
> +				memcmp(&node_comp[offset], &attach_comp[offset],
> +							node_len - offset)) {
>  			l_debug("Failed to verify app's composition data");
>  			return false;
>  		}

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

end of thread, other threads:[~2020-05-14 17:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-09  0:00 [PATCH BlueZ 0/4] Allow some composition fields update Inga Stotland
2020-05-09  0:00 ` [PATCH BlueZ 1/4] mesh: On node attach, verify element/model composition only Inga Stotland
2020-05-09 13:49   ` Gix, Brian
2020-05-14 17:05   ` Gix, Brian
2020-05-09  0:00 ` [PATCH BlueZ 2/4] mesh: Avoid saving duplicate fields in node config Inga Stotland
2020-05-09  0:00 ` [PATCH BlueZ 3/4] mesh: Allow updating CID, PID, VID & CRPL on node attach Inga Stotland
2020-05-09  0:00 ` [PATCH BlueZ 4/4] mesh: Remove redundant call to save node configuration Inga Stotland

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.