xref: /openbmc/qemu/tests/qtest/tpm-emu.h (revision 2e3408b3cc7de4e87a9adafc8c19bfce3abec947)
11e8a1faeSThomas Huth /*
21e8a1faeSThomas Huth  * Minimal TPM emulator for TPM test cases
31e8a1faeSThomas Huth  *
41e8a1faeSThomas Huth  * Copyright (c) 2018 Red Hat, Inc.
51e8a1faeSThomas Huth  *
61e8a1faeSThomas Huth  * Authors:
71e8a1faeSThomas Huth  *   Marc-André Lureau <marcandre.lureau@redhat.com>
81e8a1faeSThomas Huth  *
91e8a1faeSThomas Huth  * This work is licensed under the terms of the GNU GPL, version 2 or later.
101e8a1faeSThomas Huth  * See the COPYING file in the top-level directory.
111e8a1faeSThomas Huth  */
121e8a1faeSThomas Huth 
131e8a1faeSThomas Huth #ifndef TESTS_TPM_EMU_H
141e8a1faeSThomas Huth #define TESTS_TPM_EMU_H
151e8a1faeSThomas Huth 
161e8a1faeSThomas Huth #define TPM_RC_FAILURE 0x101
171e8a1faeSThomas Huth #define TPM2_ST_NO_SESSIONS 0x8001
181e8a1faeSThomas Huth 
19044d55dcSStefan Berger #define TPM_FAIL 9
20044d55dcSStefan Berger #define TPM_TAG_RSP_COMMAND 0xc4
21044d55dcSStefan Berger 
22266345a8SEric Auger #include "qemu/sockets.h"
23266345a8SEric Auger #include "io/channel.h"
2409b20a14SStefan Berger #include "sysemu/tpm.h"
25*907b5105SMarc-André Lureau #include "libqtest.h"
26266345a8SEric Auger 
271e8a1faeSThomas Huth struct tpm_hdr {
281e8a1faeSThomas Huth     uint16_t tag;
291e8a1faeSThomas Huth     uint32_t len;
301e8a1faeSThomas Huth     uint32_t code; /*ordinal/error */
311e8a1faeSThomas Huth     char buffer[];
321e8a1faeSThomas Huth } QEMU_PACKED;
331e8a1faeSThomas Huth 
3409b20a14SStefan Berger #ifndef CONFIG_TPM
3509b20a14SStefan Berger enum TPMVersion {
36044d55dcSStefan Berger     TPM_VERSION_1_2 = 1,
3709b20a14SStefan Berger     TPM_VERSION_2_0 = 2,
3809b20a14SStefan Berger };
3909b20a14SStefan Berger #endif
4009b20a14SStefan Berger 
419bd0e32aSStefan Berger typedef struct TPMTestState {
421e8a1faeSThomas Huth     GMutex data_mutex;
431e8a1faeSThomas Huth     GCond data_cond;
441e8a1faeSThomas Huth     bool data_cond_signal;
451e8a1faeSThomas Huth     SocketAddress *addr;
461e8a1faeSThomas Huth     QIOChannel *tpm_ioc;
471e8a1faeSThomas Huth     GThread *emu_tpm_thread;
481e8a1faeSThomas Huth     struct tpm_hdr *tpm_msg;
4909b20a14SStefan Berger     enum TPMVersion tpm_version;
509bd0e32aSStefan Berger } TPMTestState;
511e8a1faeSThomas Huth 
529bd0e32aSStefan Berger void tpm_emu_test_wait_cond(TPMTestState *s);
531e8a1faeSThomas Huth void *tpm_emu_ctrl_thread(void *data);
5458edc32cSStefan Berger bool tpm_model_is_available(const char *args, const char *tpm_if);
551e8a1faeSThomas Huth 
561e8a1faeSThomas Huth #endif /* TESTS_TPM_EMU_H */
57