Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 1 | .\" Process this file with |
| 2 | .\" groff -man -Tascii foo.1 |
| 3 | .\" |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 4 | .TH Tss2_Tcti_Device_Init 3 "MARCH 2018" Intel "TPM2 Software Stack" |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 5 | .SH NAME |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 6 | Tss2_Tcti_Device_init \- Initialization function for the device TCTI library. |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 7 | .SH SYNOPSIS |
| 8 | .B #include <tcti/tcti_device.h> |
| 9 | .sp |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 10 | .sp |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 11 | .BI "TSS2_RC Tss2_Tcti_Device_Init (TSS2_TCTI_CONTEXT " "*tctiContext" ", size_t " "*size" ", const char " "*conf" ");" |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 12 | .sp |
| 13 | The |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 14 | .BR Tss2_Tcti_Device_Init () |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 15 | function initializes a TCTI context used to communicate with the TPM device |
| 16 | driver. |
| 17 | .SH DESCRIPTION |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 18 | .BR Tss2_Tcti_Device_Init () |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 19 | attempts to initialize a caller allocated |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 20 | .I tctiContext |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 21 | of size |
| 22 | .I size |
| 23 | \&. Since the |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 24 | .I tctiContext |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 25 | must be a caller allocated buffer, the caller needs to know the size required |
| 26 | by the TCTI library. The minimum size of this context can be discovered by |
| 27 | providing |
| 28 | .BR NULL |
| 29 | for the |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 30 | .I tctiContext |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 31 | and a non- |
| 32 | .BR NULL |
| 33 | .I size |
| 34 | parameter. The initialization function will then populate the |
| 35 | .I size |
| 36 | parameter with the minimum size of the |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 37 | .I tctiContext |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 38 | buffer. The caller must then allocate a buffer of this size (or larger) and |
| 39 | call |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 40 | .B Tss2_Tcti_Device_Init () |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 41 | again providing the newly allocated |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 42 | .I tctiContext |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 43 | and the size of this context in the |
| 44 | .I size |
dantpm | 1edd111 | 2018-04-06 15:26:05 -0700 | [diff] [blame] | 45 | parameter. This pattern is common to all TCTI initialization functions. We |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 46 | provide an example of this pattern using the |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 47 | .BR Tss2_Tcti_Device_Init () |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 48 | function in the section titled |
| 49 | .B EXAMPLE. |
| 50 | .sp |
| 51 | The |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 52 | .I conf |
| 53 | parameter is a C string. If this string is |
| 54 | .BR NULL |
| 55 | then the library will use a default configuration string for the caller. |
| 56 | Alternatively, the caller may provide a configuration string that must |
| 57 | contain the path to the device node exposed by the TPM device driver. |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 58 | .sp |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 59 | Once initialized, the TCTI context returned exposes the Trusted Computing |
| 60 | Group (TCG) defined API for the lowest level communication with the TPM. |
| 61 | Using this API the caller can exchange (send / receive) TPM2 command and |
dantpm | 1edd111 | 2018-04-06 15:26:05 -0700 | [diff] [blame] | 62 | response buffers with the TPM device driver. In nearly all cases however, the |
| 63 | caller will initialize a context using this function before passing the |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 64 | context to a higher level API like the System API (SAPI), and then never touch |
| 65 | it again. |
| 66 | .sp |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 67 | TCG TSS 2.0 TPM Command |
| 68 | Transmission Interface (TCTI) API |
| 69 | Specification |
| 70 | |
| 71 | For a more thorough discussion of the TCTI API see the \*(lqTCG TSS 2.0 TPM Command |
| 72 | Transmission Interface (TCTI) API Specification\*(rq as published by |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 73 | the TCG: |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 74 | \%https://trustedcomputinggroup.org/wp-content/uploads/TSS_TCTI_Version-1.0_Revision-05_Review_END030918.pdf |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 75 | .SH RETURN VALUE |
| 76 | A successful call to |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 77 | .BR Tss2_Tcti_Device_Init () |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 78 | will return |
| 79 | .B TSS2_RC_SUCCESS. |
| 80 | An unsuccessful call will produce a response code described in section |
| 81 | .B ERRORS. |
| 82 | .SH ERRORS |
| 83 | .B TSS2_TCTI_RC_BAD_VALUE |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 84 | is returned if any parameters contain unexpected values. |
| 85 | .B TSS2_TCTI_RC_BAD_REFERENCE |
| 86 | is returned if any parameters are NULL when they should not be. |
| 87 | .B TSS2_TCTI_RC_BAD_CONTEXT |
| 88 | is returned if the size of the provided |
| 89 | .i tctiContext |
| 90 | is insufficient. |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 91 | .SH EXAMPLE |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 92 | TCTI initialization fragment: |
| 93 | .sp |
| 94 | .nf |
| 95 | #include <inttypes.h> |
| 96 | #include <stdlib.h> |
| 97 | #include <stdio.h> |
| 98 | #include <tcti/tcti_device.h> |
| 99 | |
| 100 | TSS2_RC rc; |
| 101 | TSS2_TCTI_CONTEXT *tcti_context; |
| 102 | size_t size; |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 103 | char *conf = "/dev/tpm0", |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 104 | |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 105 | rc = Tss2_Tcti_Device_Init (NULL, &size, NULL); |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 106 | if (rc != TSS2_RC_SUCCESS) { |
Doug Goldstein | 71b2473 | 2017-08-02 18:00:41 -0500 | [diff] [blame] | 107 | fprintf (stderr, "Failed to get allocation size for device TCTI " |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 108 | " context: 0x%" PRIx32 "\n", rc); |
| 109 | exit (EXIT_FAILURE); |
| 110 | } |
| 111 | tcti_context = calloc (1, size); |
| 112 | if (tcti_context == NULL) { |
| 113 | fprintf (stderr, "Allocation for TCTI context failed: %s\n", |
| 114 | strerror (errno)); |
| 115 | exit (EXIT_FAILURE); |
| 116 | } |
Philip Tricca | 5a23528 | 2018-02-27 14:59:49 -0800 | [diff] [blame] | 117 | rc = Tss2_Tcti_Device_Init (&tcti_context, &size, &conf); |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 118 | if (rc != TSS2_RC_SUCCESS) { |
Doug Goldstein | 71b2473 | 2017-08-02 18:00:41 -0500 | [diff] [blame] | 119 | fprintf (stderr, "Failed to initialize device TCTI context: " |
Philip Tricca | fe67168 | 2017-06-04 19:14:31 -0700 | [diff] [blame] | 120 | "0x%" PRIx32 "\n", rc); |
| 121 | free (tcti_context); |
| 122 | exit (EXIT_FAILURE); |
| 123 | } |
| 124 | exit (EXIT_SUCCESS); |
| 125 | .fi |