1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /******************************************************************************* 3 * Copyright 2018-2019, Fraunhofer SIT sponsored by Infineon Technologies AG 4 * All rights reserved. 5 ******************************************************************************/ 6 7 #ifdef HAVE_CONFIG_H 8 #include <config.h> 9 #endif 10 11 #include "tss2_fapi.h" 12 #include "tss2_esys.h" 13 #include "tss2_tcti.h" 14 15 #include "fapi_int.h" 16 #define LOGMODULE fapi 17 #include "util/log.h" 18 #include "util/aux_util.h" 19 20 /** One-Call function for Fapi_GetTcti 21 * 22 * Fapi_GetTcti returns the TSS2_TCTI_CONTEXT currently used by the provided FAPI_CONTEXT. 23 * The purpose is to enable advanced access to the TPM that is currently being talked to. 24 * It is especially useful in combination with Fapi_GetTpmBlobs(). 25 * 26 * Note: The application must ensure that this TSS2_TCTI_CONTEXT is not being used in parallel to 27 * the processing of a FAPI command. 28 * 29 * @param[in,out] context The FAPI_CONTEXT 30 * @param[out] tcti The TSS2_TCTI_CONTEXT used to talk to the current TPM. 31 * 32 * @retval TSS2_RC_SUCCESS: if the function call was a success. 33 * @retval TSS2_FAPI_RC_BAD_REFERENCE: if context, tcti is NULL. 34 * @retval TSS2_FAPI_RC_BAD_CONTEXT: if context corruption is detected. 35 * @retval TSS2_FAPI_RC_NO_TPM: if FAPI was started in non-TPM mode. 36 */ 37 TSS2_RC Fapi_GetTcti(FAPI_CONTEXT * context,TSS2_TCTI_CONTEXT ** tcti)38Fapi_GetTcti( 39 FAPI_CONTEXT *context, 40 TSS2_TCTI_CONTEXT **tcti) 41 { 42 LOG_TRACE("called for context:%p", context); 43 44 TSS2_RC r; 45 46 /* Check for NULL parameters */ 47 check_not_null(context); 48 check_not_null(tcti); 49 50 /* Check if FAPI was started in a non-TPM mode. */ 51 if (!context->esys) 52 return_error(TSS2_FAPI_RC_NO_TPM, "Fapi is running in non-TPM mode"); 53 54 /* Retrieve the TCTI from ESYS. */ 55 r = Esys_GetTcti(context->esys, tcti); 56 return_if_error(r, "Esys_GetTcti"); 57 58 LOG_DEBUG("finished"); 59 return r; 60 } 61