Linux bluetooth development
 help / color / mirror / Atom feed
From: Steve Brown <sbrown@cortland.com>
To: linux-bluetooth@vger.kernel.org
Cc: Steve Brown <sbrown@cortland.com>
Subject: [PATCH 1/2] mesh: prov-db: Correct json database parsing
Date: Fri, 16 Feb 2018 07:20:00 -0500	[thread overview]
Message-ID: <20180216122001.6923-1-sbrown@cortland.com> (raw)

    "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(-)

diff --git a/mesh/prov-db.c b/mesh/prov-db.c
index 012705134..019b4e173 100644
--- a/mesh/prov-db.c
+++ b/mesh/prov-db.c
@@ -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;
 
-- 
2.14.1


             reply	other threads:[~2018-02-16 12:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-16 12:20 Steve Brown [this message]
2018-02-16 12:20 ` [PATCH 2/2] mesh: node: Correct minor errors Steve Brown
2018-02-25 18:34 ` [PATCH 1/2] mesh: prov-db: Correct json database parsing Johan Hedberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180216122001.6923-1-sbrown@cortland.com \
    --to=sbrown@cortland.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox