Mesh: Fix bug in callback handling 99/239899/1 accepted/tizen/unified/20200803.122021 submit/tizen/20200731.001830
authorAnupam Roy <anupam.r@samsung.com>
Thu, 30 Jul 2020 10:41:01 +0000 (16:11 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Thu, 30 Jul 2020 10:45:09 +0000 (16:15 +0530)
This patch handles following-

- Don't create node handle and send to application
if Remote Node Discovery fails. Node Browsing
is mandatory command to discover remote node composition.
Without remote node composition, node handle
is meaningless. Therefore, send NULL in node handle
incase Node Browsing fails.

- Send Node feature information only when remote node feature
command is successful.

Change-Id: I85c78c89a22cf50cccb321f8d3d7fbeaee20a6ef
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
src/bluetooth-common.c
src/bluetooth-mesh.c

index cfc6278..f9a73e9 100644 (file)
@@ -3744,18 +3744,22 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                if (!info)
                        break;
 
-               if (_bt_get_error_code(param->result) == BT_ERROR_NONE)
+               if (_bt_get_error_code(param->result) == BT_ERROR_NONE) {
                        BT_INFO("Mesh: Remote Node Browsing: SUCCESS");
-               else
-                       BT_INFO("Mesh: Remote Node Browsing: Failed");
-               node_s = _bt_mesh_remote_node_browsed(res->net_uuid, res->dev_uuid,
-                               res->unicast, res->count);
-
-               ((bt_mesh_node_discover_status_cb)
-                       bt_event_slot_container[event_index].callback)
+                       node_s = _bt_mesh_remote_node_browsed(res->net_uuid, res->dev_uuid,
+                                       res->unicast, res->count);
+                       ((bt_mesh_node_discover_status_cb)
+                        bt_event_slot_container[event_index].callback)
                                (_bt_get_error_code(param->result), (bt_mesh_network_h) info,
-                                       (bt_mesh_node_h) node_s,
-                                       bt_event_slot_container[event_index].user_data);
+                                (bt_mesh_node_h) node_s,
+                                bt_event_slot_container[event_index].user_data);
+               } else {
+                       BT_INFO("Mesh: Remote Node Browsing: FAILED");
+                       ((bt_mesh_node_discover_status_cb)
+                        bt_event_slot_container[event_index].callback)
+                               (_bt_get_error_code(param->result), (bt_mesh_network_h) info,
+                                NULL, bt_event_slot_container[event_index].user_data);
+               }
                break;
        } case BLUETOOTH_EVENT_MESH_NODE_VENDOR_FEATURES: {
                BT_INFO("BLUETOOTH_EVENT_MESH_NODE_VENDOR_FEATURES");
@@ -3768,33 +3772,39 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us
                if (!network_s)
                        break;
 
-               if (_bt_get_error_code(param->result) == BT_ERROR_NONE)
-                       BT_INFO("Mesh: Node Vendor Features: SUCCESS");
-               else
-                       BT_INFO("Mesh: Node Vendor Features: Failed");
                node_s = _bt_mesh_remote_node_browsed(res->net_uuid, res->dev_uuid,
                                res->unicast, res->elem_count);
                if (!node_s)
                        break;
-               node_s->features.cid = res->vendor_info.companyid;
-               node_s->features.pid = res->vendor_info.versionid;
-               node_s->features.vid = res->vendor_info.vendorid;
-               node_s->features.crpl = res->vendor_info.crpl;
-
-               if (res->features.relay)
-                       node_s->features.features = BT_MESH_FEATURE_RELAY;
-               if (res->features.proxy)
-                       node_s->features.features |= BT_MESH_FEATURE_PROXY;
-               if (res->features.frnd)
-                       node_s->features.features |= BT_MESH_FEATURE_FRIEND;
-               if (res->features.lpn)
-                       node_s->features.features |= BT_MESH_FEATURE_LOWPOWER;
-
-               ((bt_mesh_node_features_cb)
-                       bt_event_slot_container[event_index].callback)
+
+               if (_bt_get_error_code(param->result) == BT_ERROR_NONE) {
+                       BT_INFO("Mesh: Node Vendor Features: SUCCESS");
+                       node_s->features.cid = res->vendor_info.companyid;
+                       node_s->features.pid = res->vendor_info.versionid;
+                       node_s->features.vid = res->vendor_info.vendorid;
+                       node_s->features.crpl = res->vendor_info.crpl;
+
+                       if (res->features.relay)
+                               node_s->features.features = BT_MESH_FEATURE_RELAY;
+                       if (res->features.proxy)
+                               node_s->features.features |= BT_MESH_FEATURE_PROXY;
+                       if (res->features.frnd)
+                               node_s->features.features |= BT_MESH_FEATURE_FRIEND;
+                       if (res->features.lpn)
+                               node_s->features.features |= BT_MESH_FEATURE_LOWPOWER;
+
+                       ((bt_mesh_node_features_cb)
+                        bt_event_slot_container[event_index].callback)
                                (_bt_get_error_code(param->result), (bt_mesh_node_h) node_s,
-                                       (bt_mesh_node_features_s*)&node_s->features,
-                                       bt_event_slot_container[event_index].user_data);
+                                (bt_mesh_node_features_s*)&node_s->features,
+                                bt_event_slot_container[event_index].user_data);
+               } else {
+                       BT_INFO("Mesh: Node Vendor Features: FAILED");
+                       ((bt_mesh_node_features_cb)
+                        bt_event_slot_container[event_index].callback)
+                               (_bt_get_error_code(param->result), (bt_mesh_node_h) node_s,
+                               NULL, bt_event_slot_container[event_index].user_data);
+               }
                break;
        } case BLUETOOTH_EVENT_MESH_NODE_KEY_CONFIGURED : {
                BT_INFO("BLUETOOTH_EVENT_MESH_NODE_KEY_CONFIGURED");
index 3ab088c..243e206 100644 (file)
@@ -2193,6 +2193,7 @@ int bt_mesh_network_discover_node(bt_mesh_network_h network,
 
        BT_MESH_VALIDATE_HANDLE(network, networks);
 
+       BT_INFO("Mesh: Discover Node with UUID[%s]", dev_uuid);
 
        /* Check if node with dev_uuid is already created */
        network_s = (bt_mesh_network_s*)network;