Skip to contentSkip to conversation

mesh: prov-db: Correct json database parsing

PATCH In review Steve Brown 2 participants 3 messages Feb 16, 2018 – Feb 25, 2018 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 mesh: prov-db: Correct json database parsing

    "composition": {
        "cid": "0002",
        "pid": "0010",
        "vid": "0001",
        "crpl": "000a",
        "features": {
            "relay": false,
            "proxy": true,
            "friend": false,
            "lowPower": false
        },
        "elements": [
            {
                "elementIndex": 0,
                "location": "0001",
                "models": ["0000", "0001", "1001"]
            }
        ]
    },
---
 mesh/prov-db.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
mesh/prov-db.c +12 -6
index 012705134..019b4e173 100644
@@ -687,7 +687,7 @@ bool prov_db_add_node_composition(struct mesh_node *node, uint8_t *data,
 
 	put_uint16(jcomp, "cid", comp->cid);
 	put_uint16(jcomp, "pid", comp->pid);
-	put_uint16(jcomp, "vid", comp->pid);
+	put_uint16(jcomp, "vid", comp->vid);
 	put_uint16(jcomp, "crpl", comp->crpl);
 
 	jfeatures = json_object_new_object();
@@ -1286,6 +1286,7 @@ static bool parse_node_composition(struct mesh_node *node, json_object *jcomp)
 {
 	json_object *jvalue;
 	json_object *jelements;
+	json_object *jfeatures;
 	json_bool enable;
 	char *str;
 	struct mesh_node_composition comp;
@@ -1305,7 +1306,7 @@ static bool parse_node_composition(struct mesh_node *node, json_object *jcomp)
 
 	str = (char *)json_object_get_string(jvalue);
 
-	if (sscanf(str, "%04hx", &comp.vid) != 1)
+	if (sscanf(str, "%04hx", &comp.pid) != 1)
 		return false;
 
 	json_object_object_get_ex(jcomp, "vid", &jvalue);
@@ -1327,19 +1328,24 @@ static bool parse_node_composition(struct mesh_node *node, json_object *jcomp)
 		return false;
 
 	/* Extract features */
-	json_object_object_get_ex(jcomp, "relay", &jvalue);
+
+	json_object_object_get_ex(jcomp, "features", &jfeatures);
+	if (!jfeatures)
+		return false;
+
+	json_object_object_get_ex(jfeatures, "relay", &jvalue);
 	enable = json_object_get_boolean(jvalue);
 	comp.relay = (enable) ? true : false;
 
-	json_object_object_get_ex(jcomp, "proxy", &jvalue);
+	json_object_object_get_ex(jfeatures, "proxy", &jvalue);
 	enable = json_object_get_boolean(jvalue);
 	comp.proxy = (enable) ? true : false;
 
-	json_object_object_get_ex(jcomp, "friend", &jvalue);
+	json_object_object_get_ex(jfeatures, "friend", &jvalue);
 	enable = json_object_get_boolean(jvalue);
 	comp.friend = (enable) ? true : false;
 
-	json_object_object_get_ex(jcomp, "lowPower", &jvalue);
+	json_object_object_get_ex(jfeatures, "lowPower", &jvalue);
 	enable = json_object_get_boolean(jvalue);
 	comp.lpn = (enable) ? true : false;
 
Signature · 1 line
2.14.1
#1 lore raw

PATCH 2/2 mesh: node: Correct minor errors

Correct length computation in node_parse_composition() Correct return value in node_set_model()
An existing node is not an error

---
 mesh/node.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mesh/node.c +2 -2
index fc8898c49..9ff741962 100644
@@ -417,7 +417,7 @@ bool node_parse_composition(struct mesh_node *node, uint8_t *data, uint16_t len)
 
 		m = *data++;
 		v = *data++;
-		len -= 4;
+		len -= 2;
 
 		while (len >= 2 && m--) {
 			mod_id = get_le16(data);
@@ -691,7 +691,7 @@ bool node_set_model(struct mesh_node *node, uint8_t ele_idx, uint32_t id)
 	l = g_list_find_custom(ele->models, GUINT_TO_POINTER(id),
 				match_model_id);
 	if (l)
-		return false;
+		return true;
 
 	model = g_malloc0(sizeof(struct mesh_model));
 	if (!model)
Signature · 1 line
2.14.1
#2 lore raw
In reply to Steve Brown

Hi Steve,

Quoted 14 lines · Steve Brown
    "composition": {
        "cid": "0002",
        "pid": "0010",
        "vid": "0001",
        "crpl": "000a",
        "features": {
            "relay": false,
            "proxy": true,
            "friend": false,
            "lowPower": false
        },
        "elements": [
            {
                "elementIndex": 0,
Quoted 8 lines
                "location": "0001",
                "models": ["0000", "0001", "1001"]
            }
        ]
    },
---
 mesh/prov-db.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

Both patches in this set have been applied. Thanks.

Johan