<commit_before>/*****************************************************************************
** Copyright (C) 2013 Intel Corporation.                                    **
**                                                                          **
** Licensed under the Apache License, Version 2.0 (the "License");          **
** you may not use this file except in compliance with the License.         **
** You may obtain a copy of the License at                                  **
**                                                                          **
**      http://www.apache.org/licenses/LICENSE-2.0                          **
**                                                                          **
** Unless required by applicable law or agreed to in writing, software      **
** distributed under the License is distributed on an "AS IS" BASIS,        **
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. **
** See the License for the specific language governing permissions and      **
** limitations under the License.                                           **
*****************************************************************************/

#ifndef __TEE_CLIENT_API_H__
#define __TEE_CLIENT_API_H__

#include <inttypes.h>
#include <stddef.h>

#define EMULATOR

#ifdef EMULATOR
#include "tee_emu_client_api.h"
#endif

/*!
 * \brief TEEC_Result Contains the return codes, the result of invoking a TEE Client API function
 */
typedef uint32_t TEEC_Result;

/*!
 * \brief RFC4122 Compliant Universally unique Resource Identifier (UUID)
 */
typedef struct {
	uint32_t timeLow;
	uint16_t timeMid;
	uint16_t timeHiAndVersion;
	uint8_t  clockSeqAndNode[8];
} TEEC_UUID;

/*!
 * \brief TEEC_TempMemoryReference A Temporary memorry Reference as used by \sa TEEC_Operation
 */
typedef struct {
	void *buffer; /*!< Pointer to the first byte of a buffer that needs to be referenced */
	size_t size;  /*!< Size of the referenced memory region */
} TEEC_TempMemoryReference;

/*!
 * \brief TEEC_RegisteredMemoryReference Uses a pre-registered memory or pre-allocated memory block
 */
typedef struct {
	TEEC_SharedMemory *parent;  /*!< Either a whole or partial memory reference */
	size_t size;                /*!< The size of the referenced memory region, in bytes */
	size_t offset;              /*!< The offset in bytes of the referenced memory region */
} TEEC_RegisteredMemoryReference;

/*!
 * \brief TEEC_Value Defines a paramater that is not referencing shared memory
 */
typedef struct {
	uint32_t a;  /*!< Paramater meaning is defined by the protocol between TA and Client */
	uint32_t b;  /*!< Paramater meaning is defined by the protocol between TA and Client */
} TEEC_Value;

/*!
 * \brief TEEC_Parameter Defines a parameter of a \sa TEEC_Operation
 */
typedef union {
	TEEC_TempMemoryReference tmpref;
	TEEC_RegisteredMemoryReference memref;
	TEEC_Value value;
} TEEC_Parameter;

/*!
 * \brief TEEC_Operation Defines the payload of either an open session or invoke command
 */
typedef struct {
	uint32_t started;    /*!< Must set to zero if the client may try to cancel the operation */
	uint32_t paramTypes; /*!< Encodes the type of each paramater that is being transfered */
	TEEC_Parameter params[4]; /*!< an array of 4 possible paramaters to share with TA */
	/* TODO what should be done about the opaque type <implementation defined> section */
} TEEC_Operation;

/*
 * 4GB default 32 bit- TODO this should be checked on platform basis, so should be possible
 * to define it it at compile time "-DTEEC_CONFIG_SHAREDMEM_MAX_SIZE=XXX"
 */
#ifndef TEEC_CONFIG_SHAREDMEM_MAX_SIZE
/*!
 * \brief TEEC_CONFIG_SHAREDMEM_MAX_SIZE The maximum size of a shared
 */
#define TEEC_CONFIG_SHAREDMEM_MAX_SIZE 0xFFFFFFFF
#endif

/* Return Codes */
#define TEEC_SUCCESS                   0x00000000
#define TEEC_ERROR_GENERIC             0xFFFF0000
#define TEEC_ERROR_ACCESS_DENIED       0xFFFF0001
#define TEEC_ERROR_CANCEL              0xFFFF0002
#define TEEC_ERROR_ACCESS_CONFLICT     0xFFFF0003
#define TEEC_ERROR_EXCESS_DATA         0xFFFF0004
#define TEEC_ERROR_BAD_FORMAT          0xFFFF0005
#define TEEC_ERROR_BAD_PARAMETERS      0xFFFF0006
#define TEEC_ERROR_BAD_STATE           0xFFFF0007
#define TEEC_ERROR_ITEM_NOT_FOUND      0xFFFF0008
#define TEEC_ERROR_NOT_IMPLEMENTED     0xFFFF0009
#define TEEC_ERROR_NOT_SUPPORTED       0xFFFF000A
#define TEEC_ERROR_NO_DATA             0xFFFF000B
#define TEEC_ERROR_OUT_OF_MEMORY       0xFFFF000C
#define TEEC_ERROR_BUSY                0xFFFF000D
#define TEEC_ERROR_COMMUNICATION       0xFFFF000E
#define TEEC_ERROR_SECURITY            0xFFFF000F
#define TEEC_ERROR_SHORT_BUFFER        0xFFFF0010

/* Return Code Origins */
#define TEEC_ORIGIN_API                0x00000001
#define TEEC_ORIGIN_COMMS              0x00000002
#define TEEC_ORIGIN_TEE                0x00000003
#define TEEC_ORIGIN_TRUSTED_APP        0x00000004

/* Shared Memory Control Flags */
#define TEEC_MEM_INPUT                 0x00000001
#define TEEC_MEM_OUTPUT                0x00000002

/* Paramater Types */
#define TEEC_NONE                      0x00000000
#define TEEC_VALUE_INPUT               0x00000001
#define TEEC_VALUE_OUTPUT              0x00000002
#define TEEC_VALUE_INOUT               0x00000003
#define TEEC_MEMREF_TEMP_INPUT         0x00000005
#define TEEC_MEMREF_TEMP_OUTPUT        0x00000006
#define TEEC_MEMREF_TEMP_INOUT         0x00000007
#define TEEC_MEMREF_WHOLE              0x0000000C
#define TEEC_MEMREF_PARTIAL_INPUT      0x0000000D
#define TEEC_MEMREF_PARTIAL_OUTPUT     0x0000000E
#define TEEC_MEMREF_PARTIAL_INOUT      0x0000000F

/* Session Login Methods */
#define TEEC_LOGIN_PUBLIC              0x00000000
#define TEEC_LOGIN_USER                0x00000001
#define TEEC_LOGIN_GROUP               0x00000002
#define TEEC_LOGIN_APPLICATION         0x00000004
#define TEEC_LOGIN_USER_APPLICATION    0x00000005
#define TEEC_LOGIN_GROUP_APPLICATION   0x00000006

/*!
 * \brief TEEC_InitializeContext
 * \param name The name of the TEE to connect to
 * \param context The context taht will be initialized by this function call
 * \return TEEC_SUCCESS on success, or another Return Code on failure
 */
TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *context);

/*!
 * \brief TEEC_FinalizeContext Finalizes an initialized context
 * \param context The initialized TEEC_Context that is to be finalized
 */
void TEEC_FinalizeContext(TEEC_Context *context);

/*!
 * \brief TEEC_RegisterSharedMemory<commit_msg>Remove Property requirement from qbs<commit_after>/*****************************************************************************
** Copyright (C) 2013 Intel Corporation.                                    **
**                                                                          **
** Licensed under the Apache License, Version 2.0 (the "License");          **
** you may not use this file except in compliance with the License.         **
** You may obtain a copy of the License at                                  **
**                                                                          **
**      http://www.apache.org/licenses/LICENSE-2.0                          **
**                                                                          **
** Unless required by applicable law or agreed to in writing, software      **
** distributed under the License is distributed on an "AS IS" BASIS,        **
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. **
** See the License for the specific language governing permissions and      **
** limitations under the License.                                           **
*****************************************************************************/

#ifndef __TEE_CLIENT_API_H__
#define __TEE_CLIENT_API_H__

#include <inttypes.h>
#include <stddef.h>

#define EMULATOR

#ifdef EMULATOR
#include "tee_emu_client_api.h"
#endif

/*!
 * \brief TEEC_Result Contains the return codes, the result of invoking a TEE Client API function
 */
typedef uint32_t TEEC_Result;

/*!
 * \brief RFC4122 Compliant Universally unique Resource Identifier (UUID)
 */
typedef struct {
	uint32_t timeLow;
	uint16_t timeMid;
	uint16_t timeHiAndVersion;
	uint8_t  clockSeqAndNode[8];
} TEEC_UUID;

/*!
 * \brief TEEC_TempMemoryReference A Temporary memorry Reference as used by \sa TEEC_Operation
 */
typedef struct {
	void *buffer; /*!< Pointer to the first byte of a buffer that needs to be referenced */
	size_t size;  /*!< Size of the referenced memory region */
} TEEC_TempMemoryReference;

/*!
 * \brief TEEC_RegisteredMemoryReference Uses a pre-registered memory or pre-allocated memory block
 */
typedef struct {
	TEEC_SharedMemory *parent;  /*!< Either a whole or partial memory reference */
	size_t size;                /*!< The size of the referenced memory region, in bytes */
	size_t offset;              /*!< The offset in bytes of the referenced memory region */
} TEEC_RegisteredMemoryReference;

/*!
 * \brief TEEC_Value Defines a paramater that is not referencing shared memory
 */
typedef struct {
	uint32_t a;  /*!< Paramater meaning is defined by the protocol between TA and Client */
	uint32_t b;  /*!< Paramater meaning is defined by the protocol between TA and Client */
} TEEC_Value;

/*!
 * \brief TEEC_Parameter Defines a parameter of a \sa TEEC_Operation
 */
typedef union {
	TEEC_TempMemoryReference tmpref;
	TEEC_RegisteredMemoryReference memref;
	TEEC_Value value;
} TEEC_Parameter;

/*!
 * \brief TEEC_Operation Defines the payload of either an open session or invoke command
 */
typedef struct {
	uint32_t started;    /*!< Must set to zero if the client may try to cancel the operation */
	uint32_t paramTypes; /*!< Encodes the type of each paramater that is being transfered */
	TEEC_Parameter params[4]; /*!< an array of 4 possible paramaters to share with TA */
	/* TODO what should be done about the opaque type <implementation defined> section */
} TEEC_Operation;

/*
 * 4GB default 32 bit- TODO this should be checked on platform basis, so should be possible
 * to define it it at compile time "-DTEEC_CONFIG_SHAREDMEM_MAX_SIZE=XXX"
 */
#ifndef TEEC_CONFIG_SHAREDMEM_MAX_SIZE
/*!
 * \brief TEEC_CONFIG_SHAREDMEM_MAX_SIZE The maximum size of a shared
 */
#define TEEC_CONFIG_SHAREDMEM_MAX_SIZE 0xFFFFFFFF
#endif

/* Return Codes */
#define TEEC_SUCCESS			0x00000000
#define TEEC_ERROR_GENERIC		0xFFFF0000
#define TEEC_ERROR_ACCESS_DENIED	0xFFFF0001
#define TEEC_ERROR_CANCEL		0xFFFF0002
#define TEEC_ERROR_ACCESS_CONFLICT	0xFFFF0003
#define TEEC_ERROR_EXCESS_DATA		0xFFFF0004
#define TEEC_ERROR_BAD_FORMAT		0xFFFF0005
#define TEEC_ERROR_BAD_PARAMETERS	0xFFFF0006
#define TEEC_ERROR_BAD_STATE		0xFFFF0007
#define TEEC_ERROR_ITEM_NOT_FOUND	0xFFFF0008
#define TEEC_ERROR_NOT_IMPLEMENTED	0xFFFF0009
#define TEEC_ERROR_NOT_SUPPORTED	0xFFFF000A
#define TEEC_ERROR_NO_DATA		0xFFFF000B
#define TEEC_ERROR_OUT_OF_MEMORY	0xFFFF000C
#define TEEC_ERROR_BUSY			0xFFFF000D
#define TEEC_ERROR_COMMUNICATION	0xFFFF000E
#define TEEC_ERROR_SECURITY		0xFFFF000F
#define TEEC_ERROR_SHORT_BUFFER		0xFFFF0010
#define TEEC_ERROR_TARGET_DEAD		0xFFFF3024

/* Return Code Origins */
#define TEEC_ORIGIN_API			0x00000001
#define TEEC_ORIGIN_COMMS		0x00000002
#define TEEC_ORIGIN_TEE			0x00000003
#define TEEC_ORIGIN_TRUSTED_APP		0x00000004

/* Shared Memory Control Flags */
#define TEEC_MEM_INPUT			0x00000001
#define TEEC_MEM_OUTPUT			0x00000002

/* Paramater Types */
#define TEEC_NONE			0x00000000
#define TEEC_VALUE_INPUT		0x00000001
#define TEEC_VALUE_OUTPUT		0x00000002
#define TEEC_VALUE_INOUT		0x00000003
#define TEEC_MEMREF_TEMP_INPUT		0x00000005
#define TEEC_MEMREF_TEMP_OUTPUT		0x00000006
#define TEEC_MEMREF_TEMP_INOUT		0x00000007
#define TEEC_MEMREF_WHOLE		0x0000000C
#define TEEC_MEMREF_PARTIAL_INPUT	0x0000000D
#define TEEC_MEMREF_PARTIAL_OUTPUT	0x0000000E
#define TEEC_MEMREF_PARTIAL_INOUT	0x0000000F

/* Session Login Methods */
#define TEEC_LOGIN_PUBLIC		0x00000000
#define TEEC_LOGIN_USER			0x00000001
#define TEEC_LOGIN_GROUP		0x00000002
#define TEEC_LOGIN_APPLICATION		0x00000004
#define TEEC_LOGIN_USER_APPLICATION	0x00000005
#define TEEC_LOGIN_GROUP_APPLICATION	0x00000006

/*!
 * \brief TEEC_InitializeContext
 * \param name The name of the TEE to connect to
 * \param context The context taht will be initialized by this function call
 * \return TEEC_SUCCESS on success, or another Return Code on failure
 */
TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *context);

/*!
 * \brief TEEC_FinalizeContext Finalizes an initialized context
 * \param context The initialized TEEC_Context that is to be finalized
 */
void TEEC_FinalizeContext(TEEC_Context *context);

/*!
 * \brief TEEC_RegisterSharedMemory
{'fraction_non_alphanumeric': 0.08501452233299317, 'fraction_numerical': 0.05173090509459141, 'mean_word_length': 3.2410119840213047, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 50, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6056109', 'n_tokens_mistral': 4374, 'n_tokens_neox': 3702, 'n_words': 1162}