Mesh: Add support for remote node reset operation 93/240993/1
authorAnupam Roy <anupam.r@samsung.com>
Thu, 13 Aug 2020 10:46:53 +0000 (16:16 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Thu, 13 Aug 2020 10:46:53 +0000 (16:16 +0530)
Change-Id: I55cf2ed663adfadc6bceca515ca8df6f2768d40e
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
include/bluetooth_internal.h
src/bluetooth-mesh.c

index e3ffdc7..1768662 100644 (file)
@@ -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.
  *
index 2a1045e..f03f7de 100644 (file)
@@ -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;