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 #include "qemu/sockets.h" 20 #include "io/channel.h" 21 #include "sysemu/tpm.h" 22 23 struct tpm_hdr { 24 uint16_t tag; 25 uint32_t len; 26 uint32_t code; /*ordinal/error */ 27 char buffer[]; 28 } QEMU_PACKED; 29 30 #ifndef CONFIG_TPM 31 enum TPMVersion { 32 TPM_VERSION_2_0 = 2, 33 }; 34 #endif 35 36 typedef struct TPMTestState { 37 GMutex data_mutex; 38 GCond data_cond; 39 bool data_cond_signal; 40 SocketAddress *addr; 41 QIOChannel *tpm_ioc; 42 GThread *emu_tpm_thread; 43 struct tpm_hdr *tpm_msg; 44 enum TPMVersion tpm_version; 45 } TPMTestState; 46 47 void tpm_emu_test_wait_cond(TPMTestState *s); 48 void *tpm_emu_ctrl_thread(void *data); 49 50 #endif /* TESTS_TPM_EMU_H */ 51