1 /* 2 * Minimal TPM emulator for TPM test cases 3 * 4 * Copyright (c) 2018 Red Hat, Inc. 5 * 6 * Authors: 7 * Marc-André Lureau <marcandre.lureau@redhat.com> 8 * 9 * This work is licensed under the terms of the GNU GPL, version 2 or later. 10 * See the COPYING file in the top-level directory. 11 */ 12 13 #ifndef TESTS_TPM_EMU_H 14 #define TESTS_TPM_EMU_H 15 16 #define TPM_RC_FAILURE 0x101 17 #define TPM2_ST_NO_SESSIONS 0x8001 18 19 #define TPM_FAIL 9 20 #define TPM_TAG_RSP_COMMAND 0xc4 21 22 #include "qemu/sockets.h" 23 #include "io/channel.h" 24 #include "sysemu/tpm.h" 25 26 struct tpm_hdr { 27 uint16_t tag; 28 uint32_t len; 29 uint32_t code; /*ordinal/error */ 30 char buffer[]; 31 } QEMU_PACKED; 32 33 #ifndef CONFIG_TPM 34 enum TPMVersion { 35 TPM_VERSION_1_2 = 1, 36 TPM_VERSION_2_0 = 2, 37 }; 38 #endif 39 40 typedef struct TPMTestState { 41 GMutex data_mutex; 42 GCond data_cond; 43 bool data_cond_signal; 44 SocketAddress *addr; 45 QIOChannel *tpm_ioc; 46 GThread *emu_tpm_thread; 47 struct tpm_hdr *tpm_msg; 48 enum TPMVersion tpm_version; 49 } TPMTestState; 50 51 void tpm_emu_test_wait_cond(TPMTestState *s); 52 void *tpm_emu_ctrl_thread(void *data); 53 54 #endif /* TESTS_TPM_EMU_H */ 55