mesh: Fix model ID prior to calling mesh config functions
authorInga Stotland <inga.stotland@intel.com>
Wed, 12 Aug 2020 19:03:16 +0000 (12:03 -0700)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 28 Dec 2020 06:20:04 +0000 (11:50 +0530)
Model IDs for SIG defined models need to be stripped off SIG_VENDOR
value used for internal housekeeping prior to calling functions
that save new model state in node configuration.

Also, remove duplicate statements for model lookup in node config.

Change-Id: I0a45e64e9b1666e531134a192b129777a63ba1f1
Signed-off-by: anuj.bhumiya <anuj.bhumiya@samsung.com>
mesh/mesh-config-json.c
mesh/model.c

index 3e45172..75ffa65 100644 (file)
@@ -170,11 +170,6 @@ static json_object *get_element_model(json_object *jnode, int ele_idx,
        size_t len;
        char buf[9];
 
-       if (!vendor)
-               snprintf(buf, 5, "%4.4x", (uint16_t)mod_id);
-       else
-               snprintf(buf, 9, "%8.8x", mod_id);
-
        if (!json_object_object_get_ex(jnode, "elements", &jelements))
                return NULL;
 
@@ -190,7 +185,7 @@ static json_object *get_element_model(json_object *jnode, int ele_idx,
                return NULL;
 
        if (!vendor) {
-               snprintf(buf, 5, "%4.4x", mod_id);
+               snprintf(buf, 5, "%4.4x", (uint16_t)mod_id);
                len = 4;
        } else {
                snprintf(buf, 9, "%8.8x", mod_id);
index 23afb93..136edb1 100644 (file)
@@ -628,6 +628,7 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id,
                                                uint16_t app_idx, bool unbind)
 {
        struct mesh_model *mod;
+       bool vendor;
        int ele_idx = node_get_element_idx(node, addr);
 
        if (ele_idx < 0)
@@ -651,11 +652,15 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id,
        if (unbind ^ has_binding(mod->bindings, app_idx))
                return MESH_STATUS_SUCCESS;
 
+       vendor = IS_VENDOR(id);
+       id = vendor ? id : MODEL_ID(id);
+
        if (unbind) {
                model_unbind_idx(node, ele_idx, mod, app_idx);
+
                if (!mesh_config_model_binding_del(node_config_get(node),
-                                                       addr, IS_VENDOR(id),
-                                                       id, app_idx))
+                                                       addr, vendor, id,
+                                                               app_idx))
                        return MESH_STATUS_STORAGE_FAIL;
 
                l_debug("Unbind key %4.4x to model %8.8x", app_idx, mod->id);
@@ -666,13 +671,12 @@ static int update_binding(struct mesh_node *node, uint16_t addr, uint32_t id,
                return MESH_STATUS_INSUFF_RESOURCES;
 
        if (!mesh_config_model_binding_add(node_config_get(node), addr,
-                                               IS_VENDOR(id), id, app_idx))
+                                               vendor, id, app_idx))
                return MESH_STATUS_STORAGE_FAIL;
 
        model_bind_idx(node, ele_idx, mod, app_idx);
 
        return MESH_STATUS_SUCCESS;
-
 }
 
 static struct mesh_virtual *add_virtual(const uint8_t *v)