Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libteec: implement OCALLs #171

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions libteec/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
project(libteec C)

set(PROJECT_VERSION "1.0.0")
set(MAJOR_VERSION 2)
set(MINOR_VERSION 0)
set(PATCH_VERSION 0)

set(PROJECT_VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}")

################################################################################
# Packages
Expand Down Expand Up @@ -37,7 +41,7 @@ add_library (teec ${SRC})

set_target_properties (teec PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
SOVERSION ${MAJOR_VERSION}
)

################################################################################
Expand Down
2 changes: 1 addition & 1 deletion libteec/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ all: libteec
################################################################################
# Teec configuration
################################################################################
MAJOR_VERSION := 1
MAJOR_VERSION := 2
MINOR_VERSION := 0
PATCH_VERSION := 0
LIB_NAME := libteec.so
Expand Down
58 changes: 57 additions & 1 deletion libteec/include/linux/tee.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@
#define TEE_IOC_BASE 0

/* Flags relating to shared memory */
#define TEE_IOCTL_SHM_NONE 0x0 /* no flags */
#define TEE_IOCTL_SHM_MAPPED 0x1 /* memory mapped in normal world */
#define TEE_IOCTL_SHM_DMA_BUF 0x2 /* dma-buf handle on shared memory */
#define TEE_IOCTL_SHM_OCALL 0x4 /* memory used for an OCALL */

#define TEE_MAX_ARG_SIZE 1024

#define TEE_GEN_CAP_GP (1 << 0)/* GlobalPlatform compliant TEE */
#define TEE_GEN_CAP_PRIVILEGED (1 << 1)/* Privileged device (for supplicant) */
#define TEE_GEN_CAP_REG_MEM (1 << 2)/* Supports registering shared memory */
#define TEE_GEN_CAP_MEMREF_NULL (1 << 3) /* Support NULL MemRef */
#define TEE_GEN_CAP_OCALL (1 << 4) /* Supports calls from TA to CA */

#define TEE_MEMREF_NULL ((__u64)-1) /* NULL MemRef Buffer */

Expand Down Expand Up @@ -167,9 +170,14 @@ struct tee_ioctl_shm_register_fd_data {
/* Meta parameter carrying extra information about the message. */
#define TEE_IOCTL_PARAM_ATTR_META 0x100

/* Parameter carrying information about an OCALL reply or request. */
#define TEE_IOCTL_PARAM_ATTR_OCALL 0x200

/* Mask of all known attr bits */
#define TEE_IOCTL_PARAM_ATTR_MASK \
(TEE_IOCTL_PARAM_ATTR_TYPE_MASK | TEE_IOCTL_PARAM_ATTR_META)
(TEE_IOCTL_PARAM_ATTR_TYPE_MASK | \
TEE_IOCTL_PARAM_ATTR_META | \
TEE_IOCTL_PARAM_ATTR_OCALL)

/*
* Matches TEEC_LOGIN_* in GP TEE Client API
Expand Down Expand Up @@ -243,6 +251,54 @@ struct tee_ioctl_open_session_arg {
#define TEE_IOC_OPEN_SESSION _IOR(TEE_IOC_MAGIC, TEE_IOC_BASE + 2, \
struct tee_ioctl_buf_data)

/*
* Command sent to the CA to request allocation of shared memory to carry the
* parameters of an OCALL
*
* [in] param[0].u.value.b requested memory size
* [out] param[0].u.value.c SHM ID
*
* Note: [in] means from driver to CA, [out], from CA to driver.
*/
#define TEE_IOCTL_OCALL_CMD_SHM_ALLOC 1

/*
* Command sent to the CA to free previously allocated shared memory.
*
* [in] param[0].u.value.c SHM ID
*
* Note: [in] means from driver to CA.
*/
#define TEE_IOCTL_OCALL_CMD_SHM_FREE 2

/*
* Command sent to the CA to execute an OCALL by Id.
*
* [any] param[0..3].u.* carry OCALL parameters
*/
#define TEE_IOCTL_OCALL_CMD_INVOKE 3

/*
* Join the Id of the function that the TEE Client API must execute on behalf of
* the CA with the Id of the command that the CA must execute
*
* As an example, TEE_IOCTL_OCALL_MAKE_PAIR(TEE_IOCTL_OCALL_CMD_INVOKE, 10)
* means that the Client API must forward a function invocation to a CA-provided
* handler, and the handler must execute command Id '10', whose meaning is up to
* the user-defined contract between the CA & TA.
*/
#define TEE_IOCTL_OCALL_MAKE_PAIR(func, cmd) \
(((__u64)(func) << 32) | (__u32)(cmd))

/*
* Get the Id of the function that the TEE Client API must execute on behalf of
* the CA
*/
#define TEE_IOCTL_OCALL_GET_FUNC(x) ((__u32)((x) >> 32))

/* Get the Id of the command that the CA must execute */
#define TEE_IOCTL_OCALL_GET_CMD(x) ((__u32)(x))

/**
* struct tee_ioctl_invoke_func_arg - Invokes a function in a Trusted
* Application
Expand Down
Loading