mirror of https://gitlab.com/qemu-project/qemu
tpm: pull tpm_util_request() out of tpm_util_test()
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
b21e6aaf4a
commit
56388eee01
|
@ -50,13 +50,13 @@ bool tpm_util_is_selftest(const uint8_t *in, uint32_t in_len)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A basic test of a TPM device. We expect a well formatted response header
|
* Send request to a TPM device. We expect a response within one second.
|
||||||
* (error response is fine) within one second.
|
|
||||||
*/
|
*/
|
||||||
static int tpm_util_test(int fd,
|
static int tpm_util_request(int fd,
|
||||||
unsigned char *request,
|
unsigned char *request,
|
||||||
size_t requestlen,
|
size_t requestlen,
|
||||||
uint16_t *return_tag)
|
unsigned char *response,
|
||||||
|
size_t responselen)
|
||||||
{
|
{
|
||||||
struct tpm_resp_hdr *resp;
|
struct tpm_resp_hdr *resp;
|
||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
|
@ -65,7 +65,6 @@ static int tpm_util_test(int fd,
|
||||||
.tv_sec = 1,
|
.tv_sec = 1,
|
||||||
.tv_usec = 0,
|
.tv_usec = 0,
|
||||||
};
|
};
|
||||||
unsigned char buf[1024];
|
|
||||||
|
|
||||||
n = write(fd, request, requestlen);
|
n = write(fd, request, requestlen);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
|
@ -84,17 +83,40 @@ static int tpm_util_test(int fd,
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = read(fd, &buf, sizeof(buf));
|
n = read(fd, response, responselen);
|
||||||
if (n < sizeof(struct tpm_resp_hdr)) {
|
if (n < sizeof(struct tpm_resp_hdr)) {
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = (struct tpm_resp_hdr *)buf;
|
resp = (struct tpm_resp_hdr *)response;
|
||||||
/* check the header */
|
/* check the header */
|
||||||
if (be32_to_cpu(resp->len) != n) {
|
if (be32_to_cpu(resp->len) != n) {
|
||||||
return -EMSGSIZE;
|
return -EMSGSIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A basic test of a TPM device. We expect a well formatted response header
|
||||||
|
* (error response is fine).
|
||||||
|
*/
|
||||||
|
static int tpm_util_test(int fd,
|
||||||
|
unsigned char *request,
|
||||||
|
size_t requestlen,
|
||||||
|
uint16_t *return_tag)
|
||||||
|
{
|
||||||
|
struct tpm_resp_hdr *resp;
|
||||||
|
unsigned char buf[1024];
|
||||||
|
ssize_t ret;
|
||||||
|
|
||||||
|
ret = tpm_util_request(fd, request, requestlen,
|
||||||
|
buf, sizeof(buf));
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
resp = (struct tpm_resp_hdr *)buf;
|
||||||
*return_tag = be16_to_cpu(resp->tag);
|
*return_tag = be16_to_cpu(resp->tag);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue