Tss2_Tcti_Device_Init.3.in 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. .\" Process this file with
  2. .\" groff -man -Tascii foo.1
  3. .\"
  4. .TH Tss2_Tcti_Device_Init 3 "MARCH 2018" "TPM2 Software Stack"
  5. .SH NAME
  6. Tss2_Tcti_Device_init \- Initialization function for the device TCTI library.
  7. .SH SYNOPSIS
  8. .B #include <tcti/tcti_device.h>
  9. .sp
  10. .sp
  11. .BI "TSS2_RC Tss2_Tcti_Device_Init (TSS2_TCTI_CONTEXT " "*tctiContext" ", size_t " "*size" ", const char " "*conf" ");"
  12. .sp
  13. The
  14. .BR Tss2_Tcti_Device_Init ()
  15. function initializes a TCTI context used to communicate with the TPM device
  16. driver.
  17. .SH DESCRIPTION
  18. .BR Tss2_Tcti_Device_Init ()
  19. attempts to initialize a caller allocated
  20. .I tctiContext
  21. of size
  22. .I size
  23. \&. Since the
  24. .I tctiContext
  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
  30. .I tctiContext
  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
  37. .I tctiContext
  38. buffer. The caller must then allocate a buffer of this size (or larger) and
  39. call
  40. .B Tss2_Tcti_Device_Init ()
  41. again providing the newly allocated
  42. .I tctiContext
  43. and the size of this context in the
  44. .I size
  45. parameter. This pattern is common to all TCTI initialization functions. We
  46. provide an example of this pattern using the
  47. .BR Tss2_Tcti_Device_Init ()
  48. function in the section titled
  49. .B EXAMPLE.
  50. .sp
  51. The
  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.
  58. .sp
  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
  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
  64. context to a higher level API like the System API (SAPI), and then never touch
  65. it again.
  66. .sp
  67. TCG TSS 2.0 TPM Command
  68. Transmission Interface (TCTI) API
  69. Specification
  70. For a more thorough discussion of the TCTI API see the \*(lqTCG TSS 2.0 TPM Command
  71. Transmission Interface (TCTI) API Specification\*(rq as published by
  72. the TCG:
  73. \%https://trustedcomputinggroup.org/wp-content/uploads/TSS_TCTI_Version-1.0_Revision-05_Review_END030918.pdf
  74. .SH RETURN VALUE
  75. A successful call to
  76. .BR Tss2_Tcti_Device_Init ()
  77. will return
  78. .B TSS2_RC_SUCCESS.
  79. An unsuccessful call will produce a response code described in section
  80. .B ERRORS.
  81. .SH ERRORS
  82. .B TSS2_TCTI_RC_BAD_VALUE
  83. is returned if any parameters contain unexpected values.
  84. .B TSS2_TCTI_RC_BAD_REFERENCE
  85. is returned if any parameters are NULL when they should not be.
  86. .B TSS2_TCTI_RC_BAD_CONTEXT
  87. is returned if the size of the provided
  88. .I tctiContext
  89. is insufficient.
  90. .SH EXAMPLE
  91. TCTI initialization fragment:
  92. .sp
  93. .nf
  94. #include <inttypes.h>
  95. #include <stdlib.h>
  96. #include <stdio.h>
  97. #include <tcti/tcti_device.h>
  98. TSS2_RC rc;
  99. TSS2_TCTI_CONTEXT *tcti_context;
  100. size_t size;
  101. char *conf = "/dev/tpm0",
  102. rc = Tss2_Tcti_Device_Init (NULL, &size, NULL);
  103. if (rc != TSS2_RC_SUCCESS) {
  104. fprintf (stderr, "Failed to get allocation size for device TCTI "
  105. " context: 0x%" PRIx32 "\n", rc);
  106. exit (EXIT_FAILURE);
  107. }
  108. tcti_context = calloc (1, size);
  109. if (tcti_context == NULL) {
  110. fprintf (stderr, "Allocation for TCTI context failed: %s\n",
  111. strerror (errno));
  112. exit (EXIT_FAILURE);
  113. }
  114. rc = Tss2_Tcti_Device_Init (&tcti_context, &size, &conf);
  115. if (rc != TSS2_RC_SUCCESS) {
  116. fprintf (stderr, "Failed to initialize device TCTI context: "
  117. "0x%" PRIx32 "\n", rc);
  118. free (tcti_context);
  119. exit (EXIT_FAILURE);
  120. }
  121. exit (EXIT_SUCCESS);
  122. .fi