Merge "Mesh: Add support for remote node reset operation" into tizen
authorPyun DoHyun <dh79.pyun@samsung.com>
Fri, 14 Aug 2020 00:26:51 +0000 (00:26 +0000)
committerGerrit Code Review <gerrit@review>
Fri, 14 Aug 2020 00:26:51 +0000 (00:26 +0000)
1  2 
include/bluetooth_internal.h
src/bluetooth-mesh.c

@@@ -4347,6 -4347,23 +4347,23 @@@ int bt_mesh_node_destroy(bt_mesh_node_
  /**
   * @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.
   *
@@@ -5077,27 -5094,6 +5094,27 @@@ int bt_mesh_model_send_msg(bt_mesh_mode
  /**
   * @internal
   * @ingroup CAPI_NETWORK_BLUETOOTH_MESH_MODULE
 + * @brief Send Group message originated by a local mesh model.
 + *
 + * @param: in: group, group handle to which message to be sent
 + * @param: in: appkey, appkey to encrypt mesh message
 + * appkey must be valid for corresponding model, i.e
 + * appkey must be bound to the model
 + * @param: in: msg_params, opcode and the message to be sent
 + * @param: in: callback, callback to be called for msg response
 + *
 + * @see bt_mesh_model_msg_params_s
 + *
 + * @since_tizen 6.0
 + * @privlevel platform
 + */
 +int bt_mesh_group_send_msg(bt_mesh_group_h group,
 +      bt_mesh_appkey_h appkey, bt_mesh_model_msg_params_s *msg_params,
 +      bt_mesh_model_msg_cb callback, void *user_data);
 +
 +/**
 + * @internal
 + * @ingroup CAPI_NETWORK_BLUETOOTH_MESH_MODULE
   * @brief Create a Mesh group with a given group address in the Local Network
   *
   * @since_tizen 6.0
diff --combined src/bluetooth-mesh.c
@@@ -720,6 -720,56 +720,56 @@@ int bt_mesh_node_create(bt_mesh_node_fe
        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;
@@@ -3005,62 -3055,6 +3055,62 @@@ int bt_mesh_model_send_msg(bt_mesh_mode
        return BT_ERROR_NONE;
  }
  
 +int bt_mesh_group_send_msg(bt_mesh_group_h group,
 +      bt_mesh_appkey_h appkey, bt_mesh_model_msg_params_s *msg_params,
 +      bt_mesh_model_msg_cb callback, void *user_data)
 +{
 +      int error_code = BT_ERROR_NONE;
 +      bt_mesh_group_s *group_s;
 +      bt_mesh_network_s *network_s;
 +      bt_mesh_appkey_s *appkey_s;
 +      bluetooth_mesh_model_msg_t req;
 +
 +      FUNC_ENTRY;
 +      BT_CHECK_MESH_SUPPORT();
 +      BT_CHECK_MESH_INIT_STATUS();
 +      BT_CHECK_INPUT_PARAMETER(group);
 +      BT_CHECK_INPUT_PARAMETER(appkey);
 +      BT_CHECK_INPUT_PARAMETER(msg_params);
 +      BT_CHECK_INPUT_PARAMETER(callback);
 +
 +      group_s = (bt_mesh_group_s*) group;
 +      BT_MESH_VALIDATE_HANDLE(group_s, group_list);
 +
 +      appkey_s = (bt_mesh_appkey_s*) appkey;
 +      BT_MESH_VALIDATE_HANDLE(appkey_s, appkey_list);
 +
 +      network_s = (bt_mesh_network_s*) group_s->parent;
 +      BT_MESH_VALIDATE_HANDLE(network_s, networks);
 +
 +      BT_INFO("Mesh: Model msg opcode: 0x%2.2X",msg_params->opcode);
 +
 +      memset(&req, 0x00, sizeof(bluetooth_mesh_model_msg_t));
 +      g_strlcpy(req.net_uuid, network_s->uuid, 33);
 +      req.primary_unicast = group_s->addr;
 +      req.appkey_idx = appkey_s->appkey_index;
 +      req.opcode = msg_params->opcode;
 +
 +      if (msg_params->data) {
 +              BT_INFO("Mesh: Group msg strlen %zd message: %s",
 +              strlen(msg_params->data), msg_params->data);
 +
 +              req.msg_len = strlen(msg_params->data);
 +              g_strlcpy(req.msg, msg_params->data, sizeof(msg_params->data) + 1);
 +      } else {
 +              req.msg_len = 0;
 +      }
 +
 +      error_code = _bt_get_error_code(bluetooth_mesh_model_send_msg(&req));
 +      if (error_code != BT_ERROR_NONE) {
 +              BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code);
 +              return error_code;
 +      }
 +
 +      FUNC_EXIT;
 +      _bt_set_cb(BT_EVENT_MESH_NODE_MODEL_EXECUTE_MSG_COMPLETED, callback, user_data);
 +      return BT_ERROR_NONE;
 +}
 +
  int bt_mesh_network_foreach_groups(bt_mesh_network_h network,
                bt_mesh_network_group_info_cb callback, void *user_data)
  {