// SPDX-License-Identifier: BSD-2-Clause /* * Copyright (c) 2018-2020, Linaro Limited */ #include #include #include #include #include #include "pkcs11_helpers.h" TEE_Result TA_CreateEntryPoint(void) { return TEE_SUCCESS; } void TA_DestroyEntryPoint(void) { } TEE_Result TA_OpenSessionEntryPoint(uint32_t __unused param_types, TEE_Param __unused params[4], void **session) { *session = NULL; return TEE_SUCCESS; } void TA_CloseSessionEntryPoint(void *session __unused) { } /* * Entry point for invocation command PKCS11_CMD_PING * * @ctrl - param memref[0] or NULL: expected NULL * @in - param memref[1] or NULL: expected NULL * @out - param memref[2] or NULL * * Return a PKCS11_CKR_* value */ static TEE_Result entry_ping(TEE_Param *ctrl, TEE_Param *in, TEE_Param *out) { const uint32_t ver[] = { PKCS11_TA_VERSION_MAJOR, PKCS11_TA_VERSION_MINOR, PKCS11_TA_VERSION_PATCH, }; size_t size = 0; if (ctrl || in) return TEE_ERROR_BAD_PARAMETERS; if (!out) return TEE_SUCCESS; size = out->memref.size; out->memref.size = sizeof(ver); if (size < sizeof(ver)) return TEE_ERROR_SHORT_BUFFER; TEE_MemMove(out->memref.buffer, ver, sizeof(ver)); return PKCS11_CKR_OK; } /* * Entry point for PKCS11 TA commands */ TEE_Result TA_InvokeCommandEntryPoint(void *tee_session __unused, uint32_t cmd, uint32_t ptypes, TEE_Param params[TEE_NUM_PARAMS]) { TEE_Param *ctrl = NULL; TEE_Param *p1_in = NULL; TEE_Param __maybe_unused *p2_in = NULL; TEE_Param *p2_out = NULL; TEE_Result res = TEE_ERROR_GENERIC; uint32_t rc = 0; /* Param#0: none or in-out buffer with serialized arguments */ switch (TEE_PARAM_TYPE_GET(ptypes, 0)) { case TEE_PARAM_TYPE_NONE: break; case TEE_PARAM_TYPE_MEMREF_INOUT: ctrl = ¶ms[0]; break; default: return TEE_ERROR_BAD_PARAMETERS; } /* Param#1: none or input data buffer */ switch (TEE_PARAM_TYPE_GET(ptypes, 1)) { case TEE_PARAM_TYPE_NONE: break; case TEE_PARAM_TYPE_MEMREF_INPUT: p1_in = ¶ms[1]; break; default: return TEE_ERROR_BAD_PARAMETERS; } /* Param#2: none or input data buffer */ switch (TEE_PARAM_TYPE_GET(ptypes, 2)) { case TEE_PARAM_TYPE_NONE: break; case TEE_PARAM_TYPE_MEMREF_INPUT: p2_in = ¶ms[2]; break; case TEE_PARAM_TYPE_MEMREF_OUTPUT: p2_out = ¶ms[2]; break; default: return TEE_ERROR_BAD_PARAMETERS; } /* Param#3: currently unused */ switch (TEE_PARAM_TYPE_GET(ptypes, 3)) { case TEE_PARAM_TYPE_NONE: break; default: return TEE_ERROR_BAD_PARAMETERS; } DMSG("%s ctrl %"PRIu32"@%p, %s %"PRIu32"@%p, %s %"PRIu32"@%p", id2str_ta_cmd(cmd), ctrl ? ctrl->memref.size : 0, ctrl ? ctrl->memref.buffer : 0, p1_in ? "in" : "---", p1_in ? p1_in->memref.size : 0, p1_in ? p1_in->memref.buffer : NULL, p2_out ? "out" : (p2_in ? "in" : "---"), p2_out ? p2_out->memref.size : (p2_in ? p2_in->memref.size : 0), p2_out ? p2_out->memref.buffer : (p2_in ? p2_in->memref.buffer : NULL)); switch (cmd) { case PKCS11_CMD_PING: rc = entry_ping(ctrl, p1_in, p2_out); break; default: EMSG("Command 0x%"PRIx32" is not supported", cmd); return TEE_ERROR_NOT_SUPPORTED; } /* Currently no output data stored in output param#0 */ if (TEE_PARAM_TYPE_GET(ptypes, 0) == TEE_PARAM_TYPE_MEMREF_INOUT) ctrl->memref.size = 0; res = pkcs2tee_error(rc); DMSG("%s rc 0x%08"PRIx32"/%s, TEE rc %"PRIx32, id2str_ta_cmd(cmd), rc, id2str_rc(rc), res); return res; }