#include "test_TA.h"
#include <tee_internal_api.h>
#include <stdio.h>
#include <string.h>


TEE_Result TA_CreateEntryPoint(void)
{
    return TEE_SUCCESS;
}

void TA_DestroyEntryPoint(void)
{
}

TEE_Result TA_OpenSessionEntryPoint(uint32_t paramTypes,
    TEE_Param params[4], void **sessionContext)
{
    (void) paramTypes;
    (void) params;
    (void) sessionContext;

    return TEE_SUCCESS;
}

void TA_CloseSessionEntryPoint(void *sessionContext)
{
    (void) sessionContext;
}

TEE_Result TA_InvokeCommandEntryPoint(void *sessionContext,
    uint32_t commandID, uint32_t paramTypes, TEE_Param params[4])
{
    (void) sessionContext;
    (void) commandID;

    if (TEE_PARAM_TYPE_GET(paramTypes,0) == TEE_PARAM_TYPE_MEMREF_INPUT)
    {
        printf("%s\n", (char*)params[0].memref.buffer);
    }

    if (TEE_PARAM_TYPE_GET(paramTypes,1) == TEE_PARAM_TYPE_MEMREF_OUTPUT)
    {
        strncpy(params[1].memref.buffer, "Hello from SWd",
                (size_t)params[1].memref.size);
        ((char*)params[1].memref.buffer)[params[1].memref.size - 1] = '\0';
    }

    return TEE_SUCCESS;
}
