[go: nahoru, domu]

blob: be113a9b6a0a260408c1ca348d016c17fd7ab54c [file] [log] [blame]
Philip Triccafe671682017-06-04 19:14:31 -07001.\" Process this file with
2.\" groff -man -Tascii foo.1
3.\"
4.TH InitDeviceTcti 3 "JUNE 2017" Intel "TPM2 Software Stack"
5.SH NAME
6InitDeviceTcti \- Initialization function for the device TCTI library.
7.SH SYNOPSIS
8.B #include <tcti/tcti_device.h>
9.sp
10.BI "typedef int (*TCTI_LOG_CALLBACK)( void " "*data" ", printf_type" "type" ", const char " "*format" ", "..." ");"
11.sp
12.nf
13typedef struct {
14 const char *device_path;
15 TCTI_LOG_CALLBACK logCallback;
16 void *logData;
17} TCTI_DEVICE_CONF;
18.fi
19.sp
20.BI "TSS2_RC InitDeviceTcti (TSS2_TCTI_CONTEXT " "*tctiContext" ", size_t " "*contextSize" ", const TCTI_DEVICE_CONF " "*config" ");"
21.sp
22The
23.BR InitDeviceTcti ()
24function initializes a TCTI context used to communicate with the TPM device
25driver.
26.SH DESCRIPTION
27.BR InitDeviceTcti ()
28attempts to initialize a caller allocated
29.I tcti_context
30of size
31.I size
32\&. Since the
33.I tcti_context
34must be a caller allocated buffer, the caller needs to know the size required
35by the TCTI library. The minimum size of this context can be discovered by
36providing
37.BR NULL
38for the
39.I tcti_context
40and a non-
41.BR NULL
42.I size
43parameter. The initialization function will then populate the
44.I size
45parameter with the minimum size of the
46.I tcti_context
47buffer. The caller must then allocate a buffer of this size (or larger) and
48call
49.B InitDeviceTcti ()
50again providing the newly allocated
51.I tcti_context
52and the size of this context in the
53.I size
54parameter. This patterm is common to all TCTI initialization functions. We
55provide an example of this pattern using the
56.BR InitDeviceTcti ()
57function in the section titled
58.B EXAMPLE.
59.sp
60The
61.I config
62parameter is a reference to an instance of the
63.B TCTI_DEVICE_CONF
64structure. The
65.I device_path
66member of this structure is a C string that contains the path to the device
67node exposed by the TPM device driver.
68.sp
69The
70.I logCallback
71parameter is a pointer to a callback function that will be called by the
72device TCTI. This is expected to be a
73.I printf
74like function.
75.sp
76The
77.I logData
78member is a void pointer to user data that will be supplied to the
79.I logCallback
80function on each invocation.
81.sp
82Once initialized, the TCTI context returned exposes the Trusted Computing
83Group (TCG) defined API for the lowest level communication with the TPM.
84Using this API the caller can exchange (send / receive) TPM2 command and
85respons buffers with the TPM device driver. In nearly all cases however, the
86caller will initialize a context using this funnction before passing the
87context to a higher level API like the System API (SAPI), and then never touch
88it again.
89.sp
90For a more thorough discussion of the TCTI API see the \*(lqTSS System Level
91API and TPM Command Transmission Interface Specification\*(rq as published by
92the TCG:
93\%https://trustedcomputinggroup.org/tss-system-level-api-tpm-command-transmission-interface-specification/
94.SH RETURN VALUE
95A successful call to
96.BR InitDeviceTcti ()
97will return
98.B TSS2_RC_SUCCESS.
99An unsuccessful call will produce a response code described in section
100.B ERRORS.
101.SH ERRORS
102.B TSS2_TCTI_RC_BAD_VALUE
103is returned if both the
104.I tcti_context
105and the
106.I size
107parameters are NULL, or if the
108.I config
109parameter is NULL.
110.SH EXAMPLE
111Logging function:
112.sp
113.nf
114int DebugPrintfCallback( void *data, printf_type type, const char *format, ...)
115{
116 va_list args;
117 int rval = 0;
118
119 va_start( args, format );
120 rval = vprintf( format, args );
121 va_end (args);
122
123 return rval;
124}
125.fi
126.sp
127TCTI initialization fragment:
128.sp
129.nf
130#include <inttypes.h>
131#include <stdlib.h>
132#include <stdio.h>
133#include <tcti/tcti_device.h>
134
135TSS2_RC rc;
136TSS2_TCTI_CONTEXT *tcti_context;
137size_t size;
138TCTI_DEVICE_CONF conf = {
139 .device_path = "/dev/tpm0",
140 .logCallback = DebugPrintfCallback,
141 .logData = NULL,
142};
143
144rc = InitDeviceTcti (NULL, &size, NULL);
145if (rc != TSS2_RC_SUCCESS) {
Doug Goldstein71b24732017-08-02 18:00:41 -0500146 fprintf (stderr, "Failed to get allocation size for device TCTI "
Philip Triccafe671682017-06-04 19:14:31 -0700147 " context: 0x%" PRIx32 "\n", rc);
148 exit (EXIT_FAILURE);
149}
150tcti_context = calloc (1, size);
151if (tcti_context == NULL) {
152 fprintf (stderr, "Allocation for TCTI context failed: %s\n",
153 strerror (errno));
154 exit (EXIT_FAILURE);
155}
156rc = InitDeviceTcti (&tcti_context, &size, &conf);
157if (rc != TSS2_RC_SUCCESS) {
Doug Goldstein71b24732017-08-02 18:00:41 -0500158 fprintf (stderr, "Failed to initialize device TCTI context: "
Philip Triccafe671682017-06-04 19:14:31 -0700159 "0x%" PRIx32 "\n", rc);
160 free (tcti_context);
161 exit (EXIT_FAILURE);
162}
163exit (EXIT_SUCCESS);
164.fi