/**
 * @file tee_param_utils.h
 * @brief Utility functionality for parsing/filling protocol data definitions
 * for SWd
 * @author Iaroslav Makarchuk (i.makarchuk@samsung.com)
 * @date Created Oct 3, 2016
 * @par In Samsung Ukraine R&D Center (SURC) under a contract between
 * @par LLC "Samsung Electronics Ukraine Company" (Kiev, Ukraine) and
 * @par "Samsung Elecrtronics Co", Ltd (Seoul, Republic of Korea)
 * @par Copyright: (c) Samsung Electronics Co, Ltd 2015. All rights reserved.
 *l
 * This software is proprietary of Samsung Electronics.
 * No part of this software, either material or conceptual may be copied
 * or distributed, transmitted, transcribed, stored in a retrieval system
 * or translated into any human or computer language in any form by any means,
 * electronic, mechanical, manual or otherwise, or disclosed to third parties
 * without the express written permission of Samsung Electronics.
 */

#ifndef TEE_PARAM_UTILS_H_
#define TEE_PARAM_UTILS_H_

#include <tee_internal_api.h>
#include <protocol.h>

/**
 * @brief Gets parameter type of the specified parameter from the types mask
 *
 * @note The function is an opposite to TEEC_PARAM_TYPES() macro. It parses the
 * types mask and returns the parameter type at the specified position.
 *
 * @param[in]      param_index   Index of the parameter whose type should be
 *                               returned
 * @param[in]      param_types   Parameters mask
 *
 * @retval Returns parameter type of the parameter at param_index position in
 *         param_types
 */
uint32_t GetParamType(uint32_t param_index, uint32_t param_types);

/**
 * @brief Fills command structure based on operation parameters
 *
 * @note The function fills command structure based on operation parameters,
 * which should be set up before.
 *
 * @param[in]      param_types   Parameters types mask
 * @param[out]     command       A pointer to command structure to be filled
 * @param[in]      params        Parameters array. It should be set up before
 *                               calling FillCommandArgs()
 *
 *
 * @retval TEE_SUCCESS              Command structure filled successfully
 * @retval TEE_ERROR_BAD_PARAMETERS Bad parameters passed to the function
 * @retval TEE_ERROR_NOT_SUPPORTED  Parameter type obtained from param_types is
 *                                  not supported
 */
TEE_Result FillCommandArgs(uint32_t param_types,
                           ProtocolCmd *command, TEE_Param params[4]);

/**
 * @brief Fills params array according to command structure
 *
 * @note The function fills params array according to the values set in command
 * structure.
 *
 * @param[in]      param_types   Parameters types mask
 * @param[in]      command       A pointer to command structure which should be
 *                               parsed.
 * @param[out]     params        Parameters array to be filled with the data.
 *
 *
 * @retval TEE_SUCCESS              Parameters set successfully
 * @retval TEE_ERROR_BAD_PARAMETERS Bad parameters passed to the function
 * @retval TEE_ERROR_NOT_SUPPORTED  Parameter type obtained from param_types is
 *                                  not supported
 */
TEE_Result FillParamValues(uint32_t param_types,
                           TEE_Param params[4], ProtocolCmd *command);

#endif /* TEE_PARAM_UTILS_H_ */
