From 59f041f509497848a78cbc6ba3748ef63dba9c66 Mon Sep 17 00:00:00 2001 From: Anupam Roy Date: Thu, 30 Jul 2020 16:11:01 +0530 Subject: [PATCH] Mesh: Fix bug in callback handling 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 --- src/bluetooth-common.c | 74 ++++++++++++++++++++++++------------------ src/bluetooth-mesh.c | 1 + 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/src/bluetooth-common.c b/src/bluetooth-common.c index cfc6278..f9a73e9 100644 --- a/src/bluetooth-common.c +++ b/src/bluetooth-common.c @@ -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"); diff --git a/src/bluetooth-mesh.c b/src/bluetooth-mesh.c index 3ab088c..243e206 100644 --- a/src/bluetooth-mesh.c +++ b/src/bluetooth-mesh.c @@ -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; -- 2.34.1