mesh: Allow updating CID, PID, VID & CRPL on node attach 26/234226/1
authorInga Stotland <inga.stotland@intel.com>
Sat, 9 May 2020 00:00:23 +0000 (17:00 -0700)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Fri, 22 May 2020 04:23:44 +0000 (09:53 +0530)
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)

Change-Id: I674c7f04f4d6c11c7b8feaca08fd6b1ccb9af9c6
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
mesh/mesh-config-json.c
mesh/mesh-config.h
mesh/node.c

index bb6866c..d64e078 100644 (file)
@@ -2058,6 +2058,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)
 {
index a5b12bb..25002f5 100644 (file)
@@ -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);
index 179552e..b89db61 100644 (file)
@@ -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;