/**
 * @file teec_param_utils.h
 * @brief Utility functionality for parsing/filling protocol data definitions
 * for NWd
 * @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 TEEC_PARAM_UTILS_H_
#define TEEC_PARAM_UTILS_H_

#include <tee_client_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[out]     command       A pointer to command structure to be filled
 * @param[in]      operation     A pointer to operation whose parameters will
 *                               be used for filling the command structure
 * @param[in]      ta_session    A pointer to the platform-dependent session
 *                               structure
 *
 *
 * @retval TEEC_SUCCESS              Command structure filled successfully
 * @retval TEEC_ERROR_BAD_PARAMETERS Bad parameters were passed to the function
 * @retval TEEC_ERROR_EXCESS_DATA    Parameter data length is too big to be sent
 */
TEEC_Result FillCommandArgs(ProtocolCmd *command,
                            TEEC_Operation *operation, void *ta_session);


/**
 * @brief Fills operation structure with the data from command structure.
 *
 * @note The function parses command structure and fills the operation
 * structure with command data.
 *
 * @param[in]     command       A pointer to command structure which will be
 *                              used to fill the operation structure
 * @param[out]    operation     A pointer to operation which will be filled
 *
 *
 * @retval TEEC_SUCCESS              Operation structure is filled successfully
 * @retval TEEC_ERROR_BAD_PARAMETERS Bad parameters were passed to the function
 * @retval TEEC_ERROR_SHORT_BUFFER   Operation data buffer is too short to
 *                                   receive the data from command
 */
TEEC_Result FillOperationArgs(TEEC_Operation *operation, ProtocolCmd *command);

void U64ToPtr(U64 *u64, void **ptr);
void PtrToU64(void *ptr,U64 *u64);

#endif /* TEEC_PARAM_UTILS_H_ */
