1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /******************************************************************************* 3 * Copyright 2017-2018, 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 <stdlib.h> 12 13 #include "tss2_esys.h" 14 15 #include "esys_iutil.h" 16 #include "test-esapi.h" 17 #define LOGMODULE test 18 #include "util/log.h" 19 #include "util/aux_util.h" 20 21 /** Test the ESAPI function Esys_FirmwareRead. 22 * 23 * Tested ESAPI commands: 24 * - Esys_FirmwareRead() (O) 25 * 26 * @param[in,out] esys_context The ESYS_CONTEXT. 27 * @retval EXIT_FAILURE 28 * @retval EXIT_SKIP 29 * @retval EXIT_SUCCESS 30 */ 31 int test_esys_firmware_read(ESYS_CONTEXT * esys_context)32test_esys_firmware_read(ESYS_CONTEXT * esys_context) 33 { 34 TSS2_RC r; 35 int failure_return = EXIT_FAILURE; 36 37 UINT32 sequenceNumber = 0; 38 TPM2B_MAX_BUFFER *fuData; 39 r = Esys_FirmwareRead( 40 esys_context, 41 ESYS_TR_NONE, 42 ESYS_TR_NONE, 43 ESYS_TR_NONE, 44 sequenceNumber, 45 &fuData); 46 47 if ((r == TPM2_RC_COMMAND_CODE) || 48 (r == (TPM2_RC_COMMAND_CODE | TSS2_RESMGR_RC_LAYER)) || 49 (r == (TPM2_RC_COMMAND_CODE | TSS2_RESMGR_TPM_RC_LAYER))) { 50 LOG_INFO("Command TPM2_FieldUpgradeData not supported by TPM."); 51 failure_return = EXIT_SKIP; 52 goto error; 53 } 54 goto_if_error(r, "Error: FirmwareRead", error); 55 56 return EXIT_SUCCESS; 57 58 error: 59 return failure_return; 60 } 61 62 int test_invoke_esapi(ESYS_CONTEXT * esys_context)63test_invoke_esapi(ESYS_CONTEXT * esys_context) { 64 return test_esys_firmware_read(esys_context); 65 } 66