diff mbox series

[BlueZ,v2,2/4] mesh: add cid/pid/vid setter

Message ID 20200130143425.5844-3-jakub.witowski@silvair.com
State New
Headers show
Series [BlueZ,v2,1/4] mesh: use static node_comp instead of the pointer | expand

Commit Message

Jakub Witowski Jan. 30, 2020, 2:34 p.m. UTC
This patch adds the setter for the CID PID and VID.
---
 mesh/mesh-config-json.c | 40 ++++++++++++++++++++++++++++++++--------
 mesh/mesh-config.h      |  2 ++
 2 files changed, 34 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/mesh/mesh-config-json.c b/mesh/mesh-config-json.c
index 5855149e3..0574c166e 100644
--- a/mesh/mesh-config-json.c
+++ b/mesh/mesh-config-json.c
@@ -1456,6 +1456,24 @@  static bool write_mode(json_object *jobj, const char *keyword, int value)
 	return true;
 }
 
+static bool write_comp_id(json_object *jobj, uint16_t cid, uint16_t pid,
+								uint16_t vid)
+{
+	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;
+
+	return true;
+}
+
 bool mesh_config_write_mode(struct mesh_config *cfg, const char *keyword,
 								int value)
 {
@@ -1595,16 +1613,10 @@  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))
+	if (!write_comp_id(jnode, node->cid, node->pid, node->vid))
 		return NULL;
 
+	/* CRPL */
 	if (!write_uint16_hex(jnode, "crpl", node->crpl))
 		return NULL;
 
@@ -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_id(struct mesh_config *cfg, uint16_t cid,
+						uint16_t pid, uint16_t vid)
+{
+	if (!cfg)
+		return false;
+
+	if (!write_comp_id(cfg->jnode, cid, pid, vid))
+		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..9a5d6e57a 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_id(struct mesh_config *cfg, uint16_t cid,
+						uint16_t pid, uint16_t vid);
 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,