diff mbox series

[2/3] mesh: add composition data setter

Message ID 20200120161114.6757-3-jakub.witowski@silvair.com
State New
Headers show
Series None | expand

Commit Message

Jakub Witowski Jan. 20, 2020, 4:11 p.m. UTC
---
 mesh/mesh-config-json.c | 46 +++++++++++++++++++++++++++++++----------
 mesh/mesh-config.h      |  2 ++
 2 files changed, 37 insertions(+), 11 deletions(-)
diff mbox series

Patch

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,