Mesh: Fix bug in fetching node vendor info 29/241129/1 accepted/tizen/unified/20200819.035932 submit/tizen/20200817.231237
authorAnupam Roy <anupam.r@samsung.com>
Mon, 17 Aug 2020 17:29:21 +0000 (22:59 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Mon, 17 Aug 2020 17:29:21 +0000 (22:59 +0530)
This patch handles following:
- Use Node's unicast address to search node in CDB.
Network UUID was wrongly used to search node in CDB,
as only local node's UUID will match with Network UUID,
rest of the nodes(provisioned) can be identified by
only their unique device UUID's. Therefore, unicast
address is the unique identifier of a node within
a network.

- NULL check was missing for node json entry before
returning not found result.

- Added few DEBUG prints.

Change-Id: I5374b21768355197e696b1ad5d12ac5d1bf143aa
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-service/services/include/bt-service-mesh-cdb.h
bt-service/services/mesh/bt-service-mesh-cdb.c
bt-service/services/mesh/bt-service-mesh-config-client.c
bt-service/services/mesh/bt-service-mesh-network.c

index 8adddc188308f901c47c8f9c3ca9812a5eaa5e9f..109c4789e8bfbcfc93cc6a5ea12610d0a8a3ac84 100644 (file)
@@ -87,10 +87,11 @@ bool _bt_mesh_conf_get_element_count(_bt_mesh_cdb_t *cfg,
 
 bool _bt_mesh_conf_load_all_keys(_bt_mesh_cdb_t* cfg);
 
-bool _bt_mesh_conf_fetch_vendor_specific_info(_bt_mesh_cdb_t *cfg,
-               uint16_t *cid, uint16_t *vid, uint16_t *version,
-                       uint16_t *crpl, int *relay, int *frnd,
-                               int *proxy, int *lpn);
+bool _bt_mesh_conf_fetch_vendor_specific_info(
+               _bt_mesh_cdb_t *cfg, uint16_t unicast,
+                       uint16_t *cid, uint16_t *vid, uint16_t *version,
+                               uint16_t *crpl, int *relay, int *frnd,
+                                       int *proxy, int *lpn);
 
 uint16_t** _bt_mesh_conf_get_all_model_info(_bt_mesh_cdb_t *cfg,
                int element_index, int *num_models);
index 22932d9ce8a46db70c0e560804398fa0786f0a3e..ca6dada301539463e51859ce1a3864914253f6f1 100644 (file)
@@ -336,12 +336,14 @@ static json_object *__mesh_get_node_by_uuid(json_object *jcfg,
        int i, sz;
 
        _bt_mesh_util_convert_hex_to_string(uuid, 16, buf, sizeof(buf));
+       BT_INFO("Mesh: Find Node with UUID [%s]", buf);
 
        json_object_object_get_ex(jcfg, "nodes", &jarray);
        if (!jarray || json_object_get_type(jarray) != json_type_array)
                return NULL;
 
        sz = json_object_array_length(jarray);
+       BT_INFO("Mesh: Total nodes present in CDB [%d]", sz);
 
        for (i = 0; i < sz; ++i) {
                json_object *jentry, *jval;
@@ -354,7 +356,7 @@ static json_object *__mesh_get_node_by_uuid(json_object *jcfg,
                str = json_object_get_string(jval);
                if (strlen(str) != 32)
                        continue;
-
+               BT_INFO("Mesh: Got one node with UUID [%s]", str);
                if (!g_strcmp0(buf, str))
                        return jentry;
        }
@@ -940,7 +942,7 @@ uint16_t** _bt_mesh_conf_get_all_model_info(_bt_mesh_cdb_t *cfg,
                return NULL;
 
        jnode = __mesh_get_node_by_uuid(jcfg, cfg->uuid);
-       if (jnode)
+       if (!jnode)
                return NULL;
 
        /* Get element array object */
@@ -998,7 +1000,7 @@ bool _bt_mesh_conf_get_element_count(_bt_mesh_cdb_t *cfg,
                return false;
 
        jnode = __mesh_get_node_by_uuid(jcfg, cfg->uuid);
-       if (jnode)
+       if (!jnode)
                return false;
 
        json_object_object_get_ex(jnode, "elements", &jarray);
@@ -1014,11 +1016,12 @@ bool _bt_mesh_conf_get_element_count(_bt_mesh_cdb_t *cfg,
        return true;
 }
 
-bool _bt_mesh_conf_fetch_vendor_specific_info(_bt_mesh_cdb_t *cfg,
-       uint16_t *cid, uint16_t *vid,
-               uint16_t *version, uint16_t *crpl,
-                       int *relay, int *friend,
-                               int *proxy, int *lpn)
+bool _bt_mesh_conf_fetch_vendor_specific_info(
+       _bt_mesh_cdb_t *cfg, uint16_t unicast,
+               uint16_t *cid, uint16_t *vid,
+                       uint16_t *version, uint16_t *crpl,
+                               int *relay, int *friend,
+                                       int *proxy, int *lpn)
 {
        json_object *jcfg;
        json_object *jnode;
@@ -1028,13 +1031,12 @@ bool _bt_mesh_conf_fetch_vendor_specific_info(_bt_mesh_cdb_t *cfg,
 
        if (!cfg)
                return false;
-
        jcfg = cfg->jcfg;
        if (!jcfg)
                return false;
 
-       jnode = __mesh_get_node_by_uuid(jcfg, cfg->uuid);
-       if (jnode)
+       jnode = __mesh_get_node_by_unicast(cfg, unicast);
+       if (!jnode)
                return false;
 
        /* Get CRPL */
@@ -1044,9 +1046,11 @@ bool _bt_mesh_conf_fetch_vendor_specific_info(_bt_mesh_cdb_t *cfg,
        str = json_object_get_string(jobj);
        if (!str)
                return false;
+
        if (sscanf(str, "%04hx", crpl) != 1)
                return false;
 
+       BT_INFO("Mesh: Got CRPL[%s]", str);
        /* Get Company ID */
        if (!json_object_object_get_ex(jnode, "cid", &jobj))
                return false;
@@ -1057,6 +1061,7 @@ bool _bt_mesh_conf_fetch_vendor_specific_info(_bt_mesh_cdb_t *cfg,
        if (sscanf(str, "%04hx", cid) != 1)
                return false;
 
+       BT_INFO("Mesh: Got CID[%s]", str);
        /* Get Vendor ID */
        if (!json_object_object_get_ex(jnode, "pid", &jobj))
                return false;
@@ -1068,6 +1073,7 @@ bool _bt_mesh_conf_fetch_vendor_specific_info(_bt_mesh_cdb_t *cfg,
        if (sscanf(str, "%04hx", vid) != 1)
                return false;
 
+       BT_INFO("Mesh: Got PID[%s]", str);
        /* Get Version ID */
        if (!json_object_object_get_ex(jnode, "vid", &jobj))
                return false;
@@ -1078,30 +1084,39 @@ bool _bt_mesh_conf_fetch_vendor_specific_info(_bt_mesh_cdb_t *cfg,
        if (sscanf(str, "%04hx", version) != 1)
                return false;
 
+       BT_INFO("Mesh: got version [%s]", str);
        jobj = json_object_object_get(jnode, "features");
 
        if (jobj) {
                if (json_object_object_get_ex(jobj, "relay", &jobjfeature)) {
-                       str = json_object_get_string(jobj);
-                       if (str)
+                       str = json_object_get_string(jobjfeature);
+                       if (str) {
                                sscanf(str, "%d", relay);
+                               BT_INFO("Mesh: Got Relay [%s]", str);
+                       }
                }
 
                if (json_object_object_get_ex(jobj, "friend", &jobjfeature)) {
-                       str = json_object_get_string(jobj);
-                       if (str)
+                       str = json_object_get_string(jobjfeature);
+                       if (str) {
                                sscanf(str, "%d", friend);
+                               BT_INFO("Mesh: Got Friend [%s]", str);
+                       }
                }
 
                if (json_object_object_get_ex(jobj, "proxy", &jobjfeature)) {
-                       str = json_object_get_string(jobj);
-                       if (str)
+                       str = json_object_get_string(jobjfeature);
+                       if (str) {
                                sscanf(str, "%d", proxy);
+                               BT_INFO("Mesh: Got Proxy[%s]", str);
+                       }
                }
                if (json_object_object_get_ex(jobj, "lowPower", &jobjfeature)) {
-                       str = json_object_get_string(jobj);
-                       if (str)
+                       str = json_object_get_string(jobjfeature);
+                       if (str) {
                                sscanf(str, "%d", lpn);
+                               BT_INFO("Mesh: Got LPN[%s]", str);
+                       }
                }
        }
        return true;
index 9999f108ca4b399aa65efcdfb13127aa30024cb6..28f5afd25ba4ddd80cfefcf22ad545bed383e15e 100644 (file)
@@ -1511,9 +1511,19 @@ void _bt_mesh_config_client_devkey_msg_handler(
                        (uint8_t *) event->net_uuid.uuid, 16, features.net_uuid,
                                BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
                features.unicast = event->source;
-               _bt_mesh_node_get_vendor_features(event->net_uuid.uuid,
-                       event->source, &features);
-
+               BT_INFO("Mesh: Net UUID [%s]", features.net_uuid);
+
+               BT_INFO("Mesh: Composition status for node unicast [0x%2.2x]",
+                       event->source);
+               if (!_bt_mesh_node_get_vendor_features(event->net_uuid.uuid,
+                       event->source, &features)) {
+                       BT_ERR("Mesh: Failed to get Vendor Specific Infor for [0x%2.2x]",
+                               event->source);
+                       result = BLUETOOTH_ERROR_INTERNAL;
+               } else {
+                       BT_INFO("Mesh: Got Feature informations for [0x%2.2x]",
+                               event->source);
+               }
                __bt_mesh_handle_pending_dev_config_request_info(result,
                        BT_MESH_NODE_GET_VENDOR_FEATURES, &features,
                                sizeof(bluetooth_mesh_node_features_t));
@@ -1663,6 +1673,7 @@ int _bt_mesh_node_discover_vendor_features(const char *app_cred, const char *sen
        oal_uuid_t net_uuid;
        uint8_t buffer[MESH_CONFIG_BUFFER_MAX_LEN];
 
+       BT_INFO("Mesh: Vendor features for Network UUID [%s]", req->net_uuid);
        _bt_mesh_util_convert_string_to_hex(req->net_uuid,
                        strlen(req->net_uuid), net_uuid.uuid, 16);
        /* Check if Node's vendor features are already svaed or not */
index 976e5a8e88037d387664afcc2faee775390e8187..24fa6fc6e8da573ac93276a6dc9954ae6a447786 100644 (file)
@@ -1272,7 +1272,7 @@ bool _bt_mesh_node_get_vendor_features(uint8_t net_uuid[],
 {
        GSList *l;
        _bt_mesh_cdb_t *cdb_cfg = NULL;
-
+       BT_INFO("Mesh: Attempt to get vendor features: unicast [0x%2.2x]", unicast);
        /* Find CDB */
        l = g_slist_find_custom(cdb_list, net_uuid,
                        __mesh_compare_app_network_uuid);
@@ -1281,7 +1281,8 @@ bool _bt_mesh_node_get_vendor_features(uint8_t net_uuid[],
 
        cdb_cfg = (_bt_mesh_cdb_t*)l->data;
 
-       return _bt_mesh_conf_fetch_vendor_specific_info(cdb_cfg,
+       BT_INFO("Mesh: Read Vendor Features from CDB");
+       return _bt_mesh_conf_fetch_vendor_specific_info(cdb_cfg, unicast,
                        &feats->vendor_info.companyid, &feats->vendor_info.vendorid,
                        &feats->vendor_info.versionid, &feats->vendor_info.crpl,
                        &feats->features.relay, &feats->features.frnd,
@@ -1402,7 +1403,7 @@ int _bt_mesh_network_load(const char *app_cred,
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       if (!_bt_mesh_conf_fetch_vendor_specific_info(cdb_cfg,
+       if (!_bt_mesh_conf_fetch_vendor_specific_info(cdb_cfg, 0x0001 /* Local Node Unicast */,
                                &node.vendor_info.companyid, &node.vendor_info.vendorid,
                                &node.vendor_info.versionid, &node.vendor_info.crpl,
                                &node.vendor_info.relay, &node.vendor_info.frnd,