/**
 * @file
 * @brief Kernel cmd support
 * @copyright (C) 2012-2016, Samsung Electronics Co., Ltd.
 * @addtogroup teesl
 * @{
 */

#ifndef __KERNEL_CMD_H__
#define __KERNEL_CMD_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <tee_internal_api.h>

/**
 * @brief Structure that contains input and output buffer pointers,
 *        its sizes and iwnotify flags, that could be used to communicate
 *        with NW Kernel.
 */
struct kernel_cmd {
    const unsigned char *msg_in;
    size_t size_in;
    unsigned char *msg_out;
    size_t size_out;
    unsigned int iwnotify_flags;
} __attribute__((__packed__));

/**
 * @brief Kernel CMD callback prototype
 * @param[in] client_id Kernel client identificator
 * @param[in] kernel_cmd Pointer to kernel_cmd structure
 * @retval 0 if success.
 *
 */
typedef int (*kernel_cmd_func_t)(unsigned int client_id, struct kernel_cmd *kernel_cmd);

/** @cond INTERNAL */
int kernel_cmd_handle(void *cmd_buf);
/** @endcond */

/**
 * @brief Registers callback to process command requests from REE Kernel
 * @param[in] func Pointer to callback function of kernel_cmd_func_t prototype
 * @retval TEE_SUCCESS no error.
 * @retval TEE_ERROR_BUSY if already registered.
 * @retval TEE_ERROR_BAD_PARAMETERS if invalid parameter passed.
 *
 * @details Example:
 * @code{.c}
 * static int TA_KernelCmd(unsigned int client_id, struct kernel_cmd *kernel_cmd)
 * {
 *      ...
 *      return 0;
 * }
 *
 * TEE_Result TA_CreateEntryPoint(void)
 * {
 *    return TEES_RegisterKernelCmdHandler(TA_KernelCmd);
 * }
 * @endcode
 */
DSO_EXPORT TEE_Result TEES_RegisterKernelCmdHandler(kernel_cmd_func_t func);

#ifdef __cplusplus
}
#endif

#endif /* __KERNEL_CMD_H__ */
/** @}*/
