17777dab0Sopenharmony_ci/*
27777dab0Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
37777dab0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
47777dab0Sopenharmony_ci * you may not use this file except in compliance with the License.
57777dab0Sopenharmony_ci * You may obtain a copy of the License at
67777dab0Sopenharmony_ci *
77777dab0Sopenharmony_ci *    http://www.apache.org/licenses/LICENSE-2.0
87777dab0Sopenharmony_ci *
97777dab0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
107777dab0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
117777dab0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127777dab0Sopenharmony_ci * See the License for the specific language governing permissions and
137777dab0Sopenharmony_ci * limitations under the License.
147777dab0Sopenharmony_ci */
157777dab0Sopenharmony_ci
167777dab0Sopenharmony_ci#ifndef TEE_CLIENT_CONSTANTS_H
177777dab0Sopenharmony_ci#define TEE_CLIENT_CONSTANTS_H
187777dab0Sopenharmony_ci/**
197777dab0Sopenharmony_ci * @addtogroup TeeClient
207777dab0Sopenharmony_ci * @{
217777dab0Sopenharmony_ci *
227777dab0Sopenharmony_ci * @brief Provides APIs for the client applications (CAs) in the Rich Execution Environment (normal mode) to
237777dab0Sopenharmony_ci * access the trusted applications (TAs) in a Trusted Execution Environment (TEE).
247777dab0Sopenharmony_ci *
257777dab0Sopenharmony_ci * @since 12
267777dab0Sopenharmony_ci * @version 1.0
277777dab0Sopenharmony_ci */
287777dab0Sopenharmony_ci
297777dab0Sopenharmony_ci/**
307777dab0Sopenharmony_ci * @file tee_client_constants.h
317777dab0Sopenharmony_ci *
327777dab0Sopenharmony_ci * @brief Defines public data and constants.
337777dab0Sopenharmony_ci *
347777dab0Sopenharmony_ci * @library libteec.so
357777dab0Sopenharmony_ci * @kit TEEKit
367777dab0Sopenharmony_ci * @syscap SystemCapability.Tee.TeeClient
377777dab0Sopenharmony_ci * @since 12
387777dab0Sopenharmony_ci * @version 1.0
397777dab0Sopenharmony_ci */
407777dab0Sopenharmony_ci
417777dab0Sopenharmony_ci/**
427777dab0Sopenharmony_ci * @brief Defines the number of <b>TEEC_Parameter</b>s in <b>TEEC_Operation</b>.
437777dab0Sopenharmony_ci *
447777dab0Sopenharmony_ci * @since 12
457777dab0Sopenharmony_ci * @version 1.0
467777dab0Sopenharmony_ci */
477777dab0Sopenharmony_ci#define TEEC_PARAM_NUM 4
487777dab0Sopenharmony_ci
497777dab0Sopenharmony_ci/**
507777dab0Sopenharmony_ci * @brief Defines the error codes returned.
517777dab0Sopenharmony_ci *
527777dab0Sopenharmony_ci * @since 12
537777dab0Sopenharmony_ci * @version 1.0
547777dab0Sopenharmony_ci */
557777dab0Sopenharmony_cienum TEEC_ReturnCode {
567777dab0Sopenharmony_ci    /** The operation is successful. */
577777dab0Sopenharmony_ci    TEEC_SUCCESS = 0x0,
587777dab0Sopenharmony_ci    /** Invalid command. The command is not supported by the TA. */
597777dab0Sopenharmony_ci    TEEC_ERROR_INVALID_CMD,
607777dab0Sopenharmony_ci    /** The TA does not exist. */
617777dab0Sopenharmony_ci    TEEC_ERROR_SERVICE_NOT_EXIST,
627777dab0Sopenharmony_ci    /** The session between the CA and TA does not exist. */
637777dab0Sopenharmony_ci    TEEC_ERROR_SESSION_NOT_EXIST,
647777dab0Sopenharmony_ci    /** The number of connections to the TA has reached the limit. */
657777dab0Sopenharmony_ci    TEEC_ERROR_SESSION_MAXIMUM,
667777dab0Sopenharmony_ci    /** The TA to be registered already exists. */
677777dab0Sopenharmony_ci    TEEC_ERROR_REGISTER_EXIST_SERVICE,
687777dab0Sopenharmony_ci    /** Secure OS framework error. */
697777dab0Sopenharmony_ci    TEEC_ERROR_TAGET_DEAD_FATAL,
707777dab0Sopenharmony_ci    /** Failed to read the file. */
717777dab0Sopenharmony_ci    TEEC_ERROR_READ_DATA,
727777dab0Sopenharmony_ci    /** Failed to write the file. */
737777dab0Sopenharmony_ci    TEEC_ERROR_WRITE_DATA,
747777dab0Sopenharmony_ci    /** Failed to truncate the file. */
757777dab0Sopenharmony_ci    TEEC_ERROR_TRUNCATE_OBJECT,
767777dab0Sopenharmony_ci    /** Failed to seek data. */
777777dab0Sopenharmony_ci    TEEC_ERROR_SEEK_DATA,
787777dab0Sopenharmony_ci    /** File synchronization error. */
797777dab0Sopenharmony_ci    TEEC_ERROR_FSYNC_DATA,
807777dab0Sopenharmony_ci    /** Failed to rename the file. */
817777dab0Sopenharmony_ci    TEEC_ERROR_RENAME_OBJECT,
827777dab0Sopenharmony_ci    /** Failed to load the TA when opening a session. */
837777dab0Sopenharmony_ci    TEEC_ERROR_TRUSTED_APP_LOAD_ERROR,
847777dab0Sopenharmony_ci    /** Failed to initialize the TA. */
857777dab0Sopenharmony_ci    TEEC_ERROR_GENERIC = 0xFFFF0000,
867777dab0Sopenharmony_ci    /** Permission verification failed. Permission verification is performed before a TEE or session is opened or
877777dab0Sopenharmony_ci     a command is sent. */
887777dab0Sopenharmony_ci    TEEC_ERROR_ACCESS_DENIED = 0xFFFF0001,
897777dab0Sopenharmony_ci    /** The operation is canceled. This error code is returned when you operate the parameter with
907777dab0Sopenharmony_ci     the cancallation flag. */
917777dab0Sopenharmony_ci    TEEC_ERROR_CANCEL = 0xFFFF0002,
927777dab0Sopenharmony_ci    /** Concurrent access causes permission conflict. Concurrent access to files in the trusted storage
937777dab0Sopenharmony_ci     service may cause this error. */
947777dab0Sopenharmony_ci    TEEC_ERROR_ACCESS_CONFLICT = 0xFFFF0003,
957777dab0Sopenharmony_ci    /** Too much data is passed in the requested operation for the TA to parse. */
967777dab0Sopenharmony_ci    TEEC_ERROR_EXCESS_DATA = 0xFFFF0004,
977777dab0Sopenharmony_ci    /** Incorrect data format. The TA failed to parse the parameters sent from the CA. */
987777dab0Sopenharmony_ci    TEEC_ERROR_BAD_FORMAT = 0xFFFF0005,
997777dab0Sopenharmony_ci    /** Invalid parameter. The input parameter is null or invalid. */
1007777dab0Sopenharmony_ci    TEEC_ERROR_BAD_PARAMETERS = 0xFFFF0006,
1017777dab0Sopenharmony_ci    /** The operation in the current state is invalid. This error code is returned if the trusted storage service is not
1027777dab0Sopenharmony_ci     initialized when a trusted storage service operation is requested. */
1037777dab0Sopenharmony_ci    TEEC_ERROR_BAD_STATE = 0xFFFF0007,
1047777dab0Sopenharmony_ci    /** The requested data is not found. */
1057777dab0Sopenharmony_ci    TEEC_ERROR_ITEM_NOT_FOUND = 0xFFFF0008,
1067777dab0Sopenharmony_ci    /** The requested operation has not been implemented yet. This error code is returned when
1077777dab0Sopenharmony_ci     <b>TEEC_RequestCancellation</b> is called. */
1087777dab0Sopenharmony_ci    TEEC_ERROR_NOT_IMPLEMENTED = 0xFFFF0009,
1097777dab0Sopenharmony_ci    /** The requested operation is valid but is not supported in this implementation. This error code is returned
1107777dab0Sopenharmony_ci     when certain algorithms of the secure encryption and decryption service, such as DSA, are requested. */
1117777dab0Sopenharmony_ci    TEEC_ERROR_NOT_SUPPORTED = 0xFFFF000A,
1127777dab0Sopenharmony_ci    /** Expected data for the requested operation is not found. */
1137777dab0Sopenharmony_ci    TEEC_ERROR_NO_DATA = 0xFFFF000B,
1147777dab0Sopenharmony_ci    /** The available system resources are insufficient. */
1157777dab0Sopenharmony_ci    TEEC_ERROR_OUT_OF_MEMORY = 0xFFFF000C,
1167777dab0Sopenharmony_ci    /** The system is busy. Some resources are exclusively used by the system. */
1177777dab0Sopenharmony_ci    TEEC_ERROR_BUSY = 0xFFFF000D,
1187777dab0Sopenharmony_ci    /** Communication between an application in the REE and a TA failed. */
1197777dab0Sopenharmony_ci    TEEC_ERROR_COMMUNICATION = 0xFFFF000E,
1207777dab0Sopenharmony_ci    /** A security fault is detected in the TEE. */
1217777dab0Sopenharmony_ci    TEEC_ERROR_SECURITY = 0xFFFF000F,
1227777dab0Sopenharmony_ci    /** The supplied buffer is too short for the output generated.
1237777dab0Sopenharmony_ci     This error may occur when {@code TEEC_MEMREF_TEMP_OUTPUT} is used. */
1247777dab0Sopenharmony_ci    TEEC_ERROR_SHORT_BUFFER = 0xFFFF0010,
1257777dab0Sopenharmony_ci    /** MAC value check error. */
1267777dab0Sopenharmony_ci    TEEC_ERROR_MAC_INVALID = 0xFFFF3071,
1277777dab0Sopenharmony_ci    /** The TA crashed. */
1287777dab0Sopenharmony_ci    TEEC_ERROR_TARGET_DEAD = 0xFFFF3024,
1297777dab0Sopenharmony_ci    /** Common error. */
1307777dab0Sopenharmony_ci    TEEC_FAIL = 0xFFFF5002
1317777dab0Sopenharmony_ci};
1327777dab0Sopenharmony_ci
1337777dab0Sopenharmony_ci/**
1347777dab0Sopenharmony_ci * @brief Defines the sources of the error codes returned.
1357777dab0Sopenharmony_ci *
1367777dab0Sopenharmony_ci * @since 12
1377777dab0Sopenharmony_ci * @version 1.0
1387777dab0Sopenharmony_ci */
1397777dab0Sopenharmony_cienum TEEC_ReturnCodeOrigin {
1407777dab0Sopenharmony_ci    /** The error code indicates an error originated from the client API. */
1417777dab0Sopenharmony_ci    TEEC_ORIGIN_API = 0x1,
1427777dab0Sopenharmony_ci    /** The error code indicates an error originated from the communication between the REE and TEE. */
1437777dab0Sopenharmony_ci    TEEC_ORIGIN_COMMS = 0x2,
1447777dab0Sopenharmony_ci    /** The error code indicates an error originated within the TEE code. */
1457777dab0Sopenharmony_ci    TEEC_ORIGIN_TEE = 0x3,
1467777dab0Sopenharmony_ci    /** The error code indicates an error originated within the TA code. */
1477777dab0Sopenharmony_ci    TEEC_ORIGIN_TRUSTED_APP = 0x4,
1487777dab0Sopenharmony_ci};
1497777dab0Sopenharmony_ci
1507777dab0Sopenharmony_ci/**
1517777dab0Sopenharmony_ci * @brief Defines the identifiers of the shared memory.
1527777dab0Sopenharmony_ci *
1537777dab0Sopenharmony_ci * @since 12
1547777dab0Sopenharmony_ci * @version 1.0
1557777dab0Sopenharmony_ci */
1567777dab0Sopenharmony_cienum TEEC_SharedMemCtl {
1577777dab0Sopenharmony_ci    /** The shared memory can carry data from CAs to TAs. */
1587777dab0Sopenharmony_ci    TEEC_MEM_INPUT = 0x1,
1597777dab0Sopenharmony_ci    /** The shared memory can carry data from TAs to CAs. */
1607777dab0Sopenharmony_ci    TEEC_MEM_OUTPUT = 0x2,
1617777dab0Sopenharmony_ci    /** The shared memory can carry data transmitted between CAs and TAs. */
1627777dab0Sopenharmony_ci    TEEC_MEM_INOUT = 0x3,
1637777dab0Sopenharmony_ci};
1647777dab0Sopenharmony_ci
1657777dab0Sopenharmony_ci/**
1667777dab0Sopenharmony_ci * @brief Defines the parameter types.
1677777dab0Sopenharmony_ci *
1687777dab0Sopenharmony_ci * @since 12
1697777dab0Sopenharmony_ci * @version 1.0
1707777dab0Sopenharmony_ci */
1717777dab0Sopenharmony_cienum TEEC_ParamType {
1727777dab0Sopenharmony_ci    /** The parameter is not used. */
1737777dab0Sopenharmony_ci    TEEC_NONE = 0x0,
1747777dab0Sopenharmony_ci    /** The parameter is a {@code TEEC_Value} tagged as input. Data flows from a CA to a TA. */
1757777dab0Sopenharmony_ci    TEEC_VALUE_INPUT = 0x01,
1767777dab0Sopenharmony_ci    /** The parameter is a {@code TEEC_Value} tagged as output. Data flows from a TA to a CA. */
1777777dab0Sopenharmony_ci    TEEC_VALUE_OUTPUT = 0x02,
1787777dab0Sopenharmony_ci    /** The parameter is a {@code TEEC_Value} tagged as both input and output. */
1797777dab0Sopenharmony_ci    TEEC_VALUE_INOUT = 0x03,
1807777dab0Sopenharmony_ci    /** The parameter is a {@code TEEC_TempMemoryReference} tagged as input. Data flows from a CA to a TA. */
1817777dab0Sopenharmony_ci    TEEC_MEMREF_TEMP_INPUT = 0x05,
1827777dab0Sopenharmony_ci    /** The parameter is a {@code TEEC_TempMemoryReference} tagged as output. Data flows from a TA to a CA. */
1837777dab0Sopenharmony_ci    TEEC_MEMREF_TEMP_OUTPUT = 0x06,
1847777dab0Sopenharmony_ci    /** The parameter is a {@code TEEC_TempMemoryReference} tagged as both input and output.
1857777dab0Sopenharmony_ci     Data is transmitted between a TA and a CA. */
1867777dab0Sopenharmony_ci    TEEC_MEMREF_TEMP_INOUT = 0x07,
1877777dab0Sopenharmony_ci    /** The parameter is a {@code TEEC_IonReference} tagged as input. Data flows from a CA to a TA**/
1887777dab0Sopenharmony_ci    TEEC_ION_INPUT = 0x08,
1897777dab0Sopenharmony_ci    /** The parameter is a {@code TEEC_IonSglistReference} tagged as input. Data flows from a CA to a TA**/
1907777dab0Sopenharmony_ci    TEEC_ION_SGLIST_INPUT = 0x09,
1917777dab0Sopenharmony_ci    /** The parameter is a {@code TEEC_RegisteredMemoryReference} that refers to the entire memory block.
1927777dab0Sopenharmony_ci     The data flow is the same as that of {@code TEEC_SharedMemCtl}. */
1937777dab0Sopenharmony_ci    TEEC_MEMREF_WHOLE = 0xc,
1947777dab0Sopenharmony_ci    /** The parameter is a {@code TEEC_RegisteredMemoryReference} tagged as input. Data flows from a CA to a TA. */
1957777dab0Sopenharmony_ci    TEEC_MEMREF_PARTIAL_INPUT = 0xd,
1967777dab0Sopenharmony_ci    /** The parameter is a {@code TEEC_RegisteredMemoryReference} tagged as output. Data flows from a TA to a CA. */
1977777dab0Sopenharmony_ci    TEEC_MEMREF_PARTIAL_OUTPUT = 0xe,
1987777dab0Sopenharmony_ci    /** The parameter is a {@code TEEC_RegisteredMemoryReference} tagged as both input and output.
1997777dab0Sopenharmony_ci     Data is transmitted between a TA and a CA. */
2007777dab0Sopenharmony_ci    TEEC_MEMREF_PARTIAL_INOUT = 0xf
2017777dab0Sopenharmony_ci};
2027777dab0Sopenharmony_ci
2037777dab0Sopenharmony_ci/**
2047777dab0Sopenharmony_ci * @brief Defines the login methods.
2057777dab0Sopenharmony_ci *
2067777dab0Sopenharmony_ci * @since 12
2077777dab0Sopenharmony_ci * @version 1.0
2087777dab0Sopenharmony_ci*/
2097777dab0Sopenharmony_cienum TEEC_LoginMethod {
2107777dab0Sopenharmony_ci    /** No login data is provided. */
2117777dab0Sopenharmony_ci    TEEC_LOGIN_PUBLIC = 0x0,
2127777dab0Sopenharmony_ci    /** The login data about the user running the CA process is provided. */
2137777dab0Sopenharmony_ci    TEEC_LOGIN_USER,
2147777dab0Sopenharmony_ci    /** The login data about the group running the CA process is provided. */
2157777dab0Sopenharmony_ci    TEEC_LOGIN_GROUP,
2167777dab0Sopenharmony_ci    /** The login data about the running CA is provided. */
2177777dab0Sopenharmony_ci    TEEC_LOGIN_APPLICATION = 0x4,
2187777dab0Sopenharmony_ci    /** The login data about the user running the CA process and about the CA are provided. */
2197777dab0Sopenharmony_ci    TEEC_LOGIN_USER_APPLICATION = 0x5,
2207777dab0Sopenharmony_ci    /** The login data about the group running the CA process and about the CA are provided. */
2217777dab0Sopenharmony_ci    TEEC_LOGIN_GROUP_APPLICATION = 0x6,
2227777dab0Sopenharmony_ci    /** Login method reserved for TEEOS. */
2237777dab0Sopenharmony_ci    TEEC_LOGIN_IDENTIFY = 0x7,
2247777dab0Sopenharmony_ci};
2257777dab0Sopenharmony_ci
2267777dab0Sopenharmony_ci/** @} */
2277777dab0Sopenharmony_ci#endif
228