From: Anupam Roy Date: Thu, 13 Aug 2020 10:46:53 +0000 (+0530) Subject: Mesh: Add support for remote node reset operation X-Git-Tag: accepted/tizen/unified/20200818.130015~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5c99f1274b34ae0a0a4508590dac9e4fb14ce663;p=platform%2Fcore%2Fapi%2Fbluetooth.git Mesh: Add support for remote node reset operation Change-Id: I55cf2ed663adfadc6bceca515ca8df6f2768d40e Signed-off-by: Anupam Roy --- diff --git a/include/bluetooth_internal.h b/include/bluetooth_internal.h index e3ffdc7..1768662 100644 --- a/include/bluetooth_internal.h +++ b/include/bluetooth_internal.h @@ -4347,6 +4347,23 @@ int bt_mesh_node_destroy(bt_mesh_node_h node_handle); /** * @internal * @ingroup CAPI_NETWORK_BLUETOOTH_MESH_MODULE + * @brief Resets the remote node identified by the node handle + * + * @remarks: Resetting local node is not allowed + * @remarks: If reset is successful, node handle will become invalid. Application + * should not use the node handle after resetting the node. + * + * @see bt_mesh_network_provision_device() + * @see bt_mesh_network_discover_node() + * + * @since_tizen 6.0 + * @privlevel platform + */ +int bt_mesh_node_reset(bt_mesh_node_h node_handle); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_MESH_MODULE * @brief API to create a mesh element. In case of Mesh Provisioner, * it will serve as a element of the local node of a Mesh Provisioner. * diff --git a/src/bluetooth-mesh.c b/src/bluetooth-mesh.c index 2a1045e..f03f7de 100644 --- a/src/bluetooth-mesh.c +++ b/src/bluetooth-mesh.c @@ -720,6 +720,56 @@ int bt_mesh_node_create(bt_mesh_node_features_s *features, return BT_ERROR_NONE; } +int bt_mesh_node_reset(bt_mesh_node_h node_handle) +{ + FUNC_ENTRY; + + bt_mesh_network_s *network_s; + bt_mesh_node_s *node_s; + bluetooth_mesh_node_info_t node; + int error_code = BT_ERROR_NONE; + + BT_CHECK_MESH_SUPPORT(); + BT_CHECK_MESH_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(node_handle); + + node_s = (bt_mesh_node_s*)node_handle; + BT_MESH_VALIDATE_HANDLE(node_s, node_list); + + network_s = node_s->parent; + BT_CHECK_INPUT_PARAMETER(network_s); + BT_MESH_VALIDATE_HANDLE(network_s, networks); + + /* Resetting a local node is not allowed */ + BT_CHECK_MESH_REMOTE(node_s); + + /* Only attached remote nodes can be resetted */ + if (!node_s->is_attached) + return BT_ERROR_INVALID_PARAMETER; + + BT_INFO("Mesh: Reset the node [0x%2.2x]", node_s->unicast); + + /* Fill node */ + memset(&node, 0x00, sizeof(bluetooth_mesh_node_t)); + g_strlcpy(node.net_uuid, network_s->uuid, 33); + node.primary_unicast = node_s->unicast; + node.num_elements = g_slist_length(node_s->elements); + + error_code = _bt_get_error_code(bluetooth_mesh_node_reset(&node)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + return error_code; + } + + /* Cleanup the Node handles */ + node_list = g_slist_remove(node_list, node_s); + g_slist_free_full(node_s->elements, __bt_mesh_free_elements); + g_free(node_s); + + FUNC_EXIT; + return error_code; +} + int bt_mesh_node_destroy(bt_mesh_node_h node_handle) { FUNC_ENTRY;