2018-02-15 16:53:56 +03:00
|
|
|
/*
|
|
|
|
* Minimal TPM emulator for TPM test cases
|
|
|
|
*
|
|
|
|
* Copyright (c) 2018 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TESTS_TPM_EMU_H
|
|
|
|
#define TESTS_TPM_EMU_H
|
|
|
|
|
|
|
|
#define TPM_RC_FAILURE 0x101
|
|
|
|
#define TPM2_ST_NO_SESSIONS 0x8001
|
|
|
|
|
2021-08-03 00:52:42 +03:00
|
|
|
#define TPM_FAIL 9
|
|
|
|
#define TPM_TAG_RSP_COMMAND 0xc4
|
|
|
|
|
2020-06-09 15:54:05 +03:00
|
|
|
#include "qemu/sockets.h"
|
|
|
|
#include "io/channel.h"
|
2021-08-03 00:52:38 +03:00
|
|
|
#include "sysemu/tpm.h"
|
2021-08-03 00:52:44 +03:00
|
|
|
#include "libqos/libqtest.h"
|
2020-06-09 15:54:05 +03:00
|
|
|
|
2018-02-15 16:53:56 +03:00
|
|
|
struct tpm_hdr {
|
|
|
|
uint16_t tag;
|
|
|
|
uint32_t len;
|
|
|
|
uint32_t code; /*ordinal/error */
|
|
|
|
char buffer[];
|
|
|
|
} QEMU_PACKED;
|
|
|
|
|
2021-08-03 00:52:38 +03:00
|
|
|
#ifndef CONFIG_TPM
|
|
|
|
enum TPMVersion {
|
2021-08-03 00:52:42 +03:00
|
|
|
TPM_VERSION_1_2 = 1,
|
2021-08-03 00:52:38 +03:00
|
|
|
TPM_VERSION_2_0 = 2,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2021-08-03 00:52:37 +03:00
|
|
|
typedef struct TPMTestState {
|
2018-05-04 17:34:46 +03:00
|
|
|
GMutex data_mutex;
|
|
|
|
GCond data_cond;
|
2018-09-07 18:47:06 +03:00
|
|
|
bool data_cond_signal;
|
2018-02-15 16:53:56 +03:00
|
|
|
SocketAddress *addr;
|
|
|
|
QIOChannel *tpm_ioc;
|
|
|
|
GThread *emu_tpm_thread;
|
|
|
|
struct tpm_hdr *tpm_msg;
|
2021-08-03 00:52:38 +03:00
|
|
|
enum TPMVersion tpm_version;
|
2021-08-03 00:52:37 +03:00
|
|
|
} TPMTestState;
|
2018-02-15 16:53:56 +03:00
|
|
|
|
2021-08-03 00:52:37 +03:00
|
|
|
void tpm_emu_test_wait_cond(TPMTestState *s);
|
2018-02-15 16:53:56 +03:00
|
|
|
void *tpm_emu_ctrl_thread(void *data);
|
2021-08-03 00:52:44 +03:00
|
|
|
bool tpm_model_is_available(const char *args, const char *tpm_if);
|
2018-02-15 16:53:56 +03:00
|
|
|
|
2019-03-15 17:51:23 +03:00
|
|
|
#endif /* TESTS_TPM_EMU_H */
|