linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Witowski <jakub.witowski@silvair.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH 3/3] mesh: allow to reattach with new composition data
Date: Mon, 20 Jan 2020 17:11:14 +0100	[thread overview]
Message-ID: <20200120161114.6757-4-jakub.witowski@silvair.com> (raw)
In-Reply-To: <20200120161114.6757-1-jakub.witowski@silvair.com>

---
 mesh/node.c | 40 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 35 insertions(+), 5 deletions(-)

diff --git a/mesh/node.c b/mesh/node.c
index 6fe70742d..f9a2d5722 100644
--- a/mesh/node.c
+++ b/mesh/node.c
@@ -47,6 +47,12 @@
 
 #define MIN_COMP_SIZE 14
 
+/* Composition data header size contains the length of belows:
+ * CID, PID, VID, CRPL and Feature bits
+ */
+#define COMP_HDR_SIZE 10
+#define COMP_FEATURE_BITS_SIZE 2
+
 #define MESH_NODE_PATH_PREFIX "/node"
 
 /* Default values for a new locally created node */
@@ -1394,15 +1400,39 @@ 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;
-
+		/* Ignore CID, VID, PID, CRPL and feature bits
+		 * in Composition Compare
+		 */
 		if (node_len != attach_len ||
-				memcmp(node_comp, attach_comp, node_len)) {
+			memcmp(node_comp + COMP_HDR_SIZE,
+						attach_comp + COMP_HDR_SIZE,
+						node_len - COMP_HDR_SIZE)) {
 			l_debug("Failed to verify app's composition data");
 			return false;
 		}
+
+		/* Compare CID, VID, PID and CRPL */
+		if (!memcmp(node_comp, attach_comp,
+					COMP_HDR_SIZE - COMP_FEATURE_BITS_SIZE))
+			return true;
+
+		l_debug("Composition data update");
+
+		if (!mesh_config_write_comp(req->attach->cfg,
+				req->node->comp.cid, req->node->comp.pid,
+				req->node->comp.vid, req->node->comp.crpl)) {
+
+			l_debug("Failed to update composition data");
+			return false;
+		}
+
+		if (!mesh_config_save(req->attach->cfg, true, NULL, NULL)) {
+			l_debug("Failed to store composition data");
+			return false;
+		}
+
+		memcpy(&req->attach->comp, &req->node->comp,
+					sizeof(struct node_composition));
 	}
 
 	return true;
-- 
2.20.1


  parent reply	other threads:[~2020-01-20 16:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-20 16:11 [PATCH 0/3] Allow to reattach with new composition data Jakub Witowski
2020-01-20 16:11 ` [PATCH 1/3] mesh: use static node_comp instead of the pointer Jakub Witowski
2020-01-20 16:11 ` [PATCH 2/3] mesh: add composition data setter Jakub Witowski
2020-01-20 16:11 ` Jakub Witowski [this message]
2020-01-20 17:17 ` [PATCH 0/3] Allow to reattach with new composition data Gix, Brian
2020-01-21 10:59   ` jakub.witowski
2020-01-21 18:21     ` Stotland, Inga
2020-01-21 20:05       ` Michał Lowas-Rzechonek
2020-01-22 13:53         ` jakub.witowski
2020-01-22 18:02   ` Michał Lowas-Rzechonek
2020-01-22 18:03     ` Michał Lowas-Rzechonek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200120161114.6757-4-jakub.witowski@silvair.com \
    --to=jakub.witowski@silvair.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).