Skip to content

Commit

Permalink
swtpm_ioctl: Use ptm_cap_n for non-CUSE PTM_GET_CAPABILITY response
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
  • Loading branch information
stefanberger committed Oct 11, 2024
1 parent 47c96a0 commit 3a0ff17
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/swtpm_ioctl/tpm_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
#define devtoh32(is_chardev, x) (is_chardev ? x : be32toh(x))
#define htodev32(is_chardev, x) (is_chardev ? x : htobe32(x))

#define devtoh64(is_chardev, x) (is_chardev ? x : be64toh(x))
#define htodev64(is_chardev, x) (is_chardev ? x : htobe64(x))

/* for OpenBSD */
Expand Down Expand Up @@ -926,6 +925,7 @@ int main(int argc, char *argv[])
ptm_reset_est reset_est;
ptm_loc loc;
ptm_cap cap;
ptm_cap_n cap_n;
ptm_res res;
ptm_init init;
ptm_getconfig cfg;
Expand Down Expand Up @@ -1120,17 +1120,21 @@ int main(int argc, char *argv[])
}

if (!strcmp(command, "-c")) {
uint32_t caps;
n = ctrlcmd(fd, PTM_GET_CAPABILITY, &cap, 0, sizeof(cap));
if (n < 0) {
fprintf(stderr,
"Could not execute PTM_GET_CAPABILITY: "
"%s\n", strerror(errno));
goto exit;
}
/* no tpm_result here */
printf("ptm capability is 0x%" PRIx64 "\n",
(uint64_t)devtoh64(is_chardev, cap));

if (is_chardev) {
caps = (uint32_t)cap;
} else {
memcpy(&cap_n, &cap, sizeof(cap_n));
caps = be32toh(cap_n.u.resp.caps);
}
printf("ptm capability is 0x%x\n", caps);
} else if (!strcmp(command, "-i")) {
init.u.req.init_flags = htodev32(is_chardev,
PTM_INIT_FLAG_DELETE_VOLATILE);
Expand Down

0 comments on commit 3a0ff17

Please sign in to comment.