blob: 85e310c355f5f1eff8a875830e4a740edfc1cbc0 [file] [log] [blame]
Andreas Fuchs6ab3fd82018-03-28 12:23:19 +02001#include <stdbool.h>
2#include <stdlib.h>
Andreas Fuchsc0c19c62018-03-28 12:35:30 +02003#include <inttypes.h>
Andreas Fuchs6ab3fd82018-03-28 12:23:19 +02004
5#include "tss2_sys.h"
6
7#define LOGMODULE test
8#include "util/log.h"
9#include "test-options.h"
10#include "context-util.h"
11
Andreas Fuchsc0c19c62018-03-28 12:35:30 +020012#define TAB_SIZE(x) (sizeof(x)/sizeof(x[0]))
13
Andreas Fuchs6ab3fd82018-03-28 12:23:19 +020014int
15main (int argc, char *argv[])
16{
17 TSS2_RC rc;
18 TSS2_SYS_CONTEXT *sapi_context;
19
20 test_opts_t opts = {
21 .tcti_type = TCTI_DEFAULT,
22 .device_file = DEVICE_PATH_DEFAULT,
23 .socket_address = HOSTNAME_DEFAULT,
24 .socket_port = PORT_DEFAULT,
25 };
26
27 get_test_opts_from_env (&opts);
28 if (sanity_check_test_opts (&opts) != 0)
29 exit (1);
30
31 sapi_context = sapi_init_from_opts (&opts);
32 if (sapi_context == NULL)
33 exit (1);
34
Andreas Fuchsc0c19c62018-03-28 12:35:30 +020035 TPMS_CAPABILITY_DATA caps;
36
Andreas Fuchs6ab3fd82018-03-28 12:23:19 +020037 rc = Tss2_Sys_GetCapability(sapi_context, NULL, TPM2_CAP_HANDLES,
Andreas Fuchsc0c19c62018-03-28 12:35:30 +020038 TPM2_HR_TRANSIENT,
39 TAB_SIZE(caps.data.handles.handle), NULL,
40 &caps, NULL);
Andreas Fuchs6ab3fd82018-03-28 12:23:19 +020041 if (rc != TSS2_RC_SUCCESS) {
Andreas Fuchsc0c19c62018-03-28 12:35:30 +020042 LOG_ERROR("TPM GetCapabilities FAILED! Response Code : 0x%"PRIx32, rc);
Andreas Fuchs6ab3fd82018-03-28 12:23:19 +020043 exit(1);
44 }
45
Andreas Fuchsc0c19c62018-03-28 12:35:30 +020046
Andreas Fuchs6ab3fd82018-03-28 12:23:19 +020047 sapi_teardown_full (sapi_context);
48
Andreas Fuchsc0c19c62018-03-28 12:35:30 +020049 if (caps.data.handles.count) {
Andreas Fuchs6ab3fd82018-03-28 12:23:19 +020050 LOG_ERROR("TPM contains transient entries");
Andreas Fuchs450cf0b2018-03-29 15:48:27 +020051 for (UINT32 i = 0; i < caps.data.handles.count; i++)
Andreas Fuchsc0c19c62018-03-28 12:35:30 +020052 LOG_ERROR("Handle %"PRIx32, caps.data.handles.handle[i]);
Andreas Fuchs6ab3fd82018-03-28 12:23:19 +020053 return 1;
54 }
Andreas Fuchsc0c19c62018-03-28 12:35:30 +020055
Andreas Fuchs6ab3fd82018-03-28 12:23:19 +020056 return 0;
57}