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 2/3] mesh: add composition data setter
Date: Mon, 20 Jan 2020 17:11:13 +0100	[thread overview]
Message-ID: <20200120161114.6757-3-jakub.witowski@silvair.com> (raw)
In-Reply-To: <20200120161114.6757-1-jakub.witowski@silvair.com>

---
 mesh/mesh-config-json.c | 46 +++++++++++++++++++++++++++++++----------
 mesh/mesh-config.h      |  2 ++
 2 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index 5855149e3..ee42cf7df 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
@@ -1456,6 +1456,27 @@ static bool write_mode(json_object *jobj, const char *keyword, int value)
 	return true;
 }
 
+static bool write_comp(json_object *jobj, uint16_t cid, uint16_t pid,
+						uint16_t vid, uint16_t crpl)
+{
+	if (!jobj)
+		return false;
+
+	if (!write_uint16_hex(jobj, "cid", cid))
+		return false;
+
+	if (!write_uint16_hex(jobj, "pid", pid))
+		return false;
+
+	if (!write_uint16_hex(jobj, "vid", vid))
+		return false;
+
+	if (!write_uint16_hex(jobj, "crpl", crpl))
+		return false;
+
+	return true;
+}
+
 bool mesh_config_write_mode(struct mesh_config *cfg, const char *keyword,
 								int value)
 {
@@ -1595,17 +1616,8 @@ static struct mesh_config *create_config(const char *cfg_path,
 
 	jnode = json_object_new_object();
 
-	/* CID, PID, VID, crpl */
-	if (!write_uint16_hex(jnode, "cid", node->cid))
-		return NULL;
-
-	if (!write_uint16_hex(jnode, "pid", node->pid))
-		return NULL;
-
-	if (!write_uint16_hex(jnode, "vid", node->vid))
-		return NULL;
-
-	if (!write_uint16_hex(jnode, "crpl", node->crpl))
+	/* CID, PID, VID, CRPL */
+	if (!write_comp(jnode, node->cid, node->pid, node->vid, node->crpl))
 		return NULL;
 
 	/* Features: relay, LPN, friend, proxy*/
@@ -2052,6 +2064,18 @@ bool mesh_config_write_ttl(struct mesh_config *cfg, uint8_t ttl)
 	return save_config(cfg->jnode, cfg->node_dir_path);
 }
 
+bool mesh_config_write_comp(struct mesh_config *cfg, uint16_t cid, uint16_t pid,
+						uint16_t vid, uint16_t crpl)
+{
+	if (!cfg)
+		return false;
+
+	if (!write_comp(cfg->jnode, cid, pid, vid, crpl))
+		return false;
+
+	return true;
+}
+
 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..5a003b95c 100644
--- a/mesh/mesh-config.h
+++ b/mesh/mesh-config.h
@@ -135,6 +135,8 @@ bool mesh_config_write_unicast(struct mesh_config *cfg, uint16_t unicast);
 bool mesh_config_write_relay_mode(struct mesh_config *cfg, uint8_t mode,
 					uint8_t count, uint16_t interval);
 bool mesh_config_write_ttl(struct mesh_config *cfg, uint8_t ttl);
+bool mesh_config_write_comp(struct mesh_config *cfg, uint16_t cid, uint16_t pid,
+						uint16_t vid, uint16_t crpl);
 bool mesh_config_write_mode(struct mesh_config *cfg, const char *keyword,
 								int value);
 bool mesh_config_model_binding_add(struct mesh_config *cfg, uint16_t ele_addr,
-- 
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 ` Jakub Witowski [this message]
2020-01-20 16:11 ` [PATCH 3/3] mesh: allow to reattach with new composition data Jakub Witowski
2020-01-20 17:17 ` [PATCH 0/3] Allow " 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-3-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).