tlcl.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
  2. * Use of this source code is governed by a BSD-style license that can be
  3. * found in the LICENSE file.
  4. */
  5. /*
  6. * TPM Lightweight Command Library.
  7. *
  8. * A low-level library for interfacing to TPM hardware or an emulator.
  9. */
  10. #ifndef TPM_LITE_TLCL_H_
  11. #define TPM_LITE_TLCL_H_
  12. #include <stdint.h>
  13. #include "tss_constants.h"
  14. /*****************************************************************************/
  15. /* Functions implemented in tlcl.c */
  16. /**
  17. * Call this first. Returns 0 if success, nonzero if error.
  18. */
  19. uint32_t TlclLibInit(void);
  20. /**
  21. * Call this on shutdown. Returns 0 if success, nonzero if error.
  22. */
  23. uint32_t TlclLibClose(void);
  24. /* Low-level operations */
  25. /**
  26. * Perform a raw TPM request/response transaction.
  27. */
  28. uint32_t TlclSendReceive(const uint8_t *request, uint8_t *response,
  29. int max_length);
  30. /**
  31. * Return the size of a TPM request or response packet.
  32. */
  33. int TlclPacketSize(const uint8_t *packet);
  34. /* Commands */
  35. /**
  36. * Send a TPM_Startup(ST_CLEAR). The TPM error code is returned (0 for
  37. * success).
  38. */
  39. uint32_t TlclStartup(void);
  40. /**
  41. * Save the TPM state. Normally done by the kernel before a suspend, included
  42. * here for tests. The TPM error code is returned (0 for success).
  43. */
  44. uint32_t TlclSaveState(void);
  45. /**
  46. * Resume by sending a TPM_Startup(ST_STATE). The TPM error code is returned
  47. * (0 for success).
  48. */
  49. uint32_t TlclResume(void);
  50. /**
  51. * Run the self test.
  52. *
  53. * Note---this is synchronous. To run this in parallel with other firmware,
  54. * use ContinueSelfTest(). The TPM error code is returned.
  55. */
  56. uint32_t TlclSelfTestFull(void);
  57. /**
  58. * Run the self test in the background.
  59. */
  60. uint32_t TlclContinueSelfTest(void);
  61. /**
  62. * Define a space with permission [perm]. [index] is the index for the space,
  63. * [size] the usable data size. The TPM error code is returned.
  64. */
  65. uint32_t TlclDefineSpace(uint32_t index, uint32_t perm, uint32_t size);
  66. /**
  67. * Write [length] bytes of [data] to space at [index]. The TPM error code is
  68. * returned.
  69. */
  70. uint32_t TlclWrite(uint32_t index, const void *data, uint32_t length);
  71. /**
  72. * Read [length] bytes from space at [index] into [data]. The TPM error code
  73. * is returned.
  74. */
  75. uint32_t TlclRead(uint32_t index, void *data, uint32_t length);
  76. /**
  77. * Read PCR at [index] into [data]. [length] must be TPM_PCR_DIGEST or
  78. * larger. The TPM error code is returned.
  79. */
  80. uint32_t TlclPCRRead(uint32_t index, void *data, uint32_t length);
  81. /**
  82. * Write-lock space at [index]. The TPM error code is returned.
  83. */
  84. uint32_t TlclWriteLock(uint32_t index);
  85. /**
  86. * Read-lock space at [index]. The TPM error code is returned.
  87. */
  88. uint32_t TlclReadLock(uint32_t index);
  89. /**
  90. * Assert physical presence in software. The TPM error code is returned.
  91. */
  92. uint32_t TlclAssertPhysicalPresence(void);
  93. /**
  94. * Enable the physical presence command. The TPM error code is returned.
  95. */
  96. uint32_t TlclPhysicalPresenceCMDEnable(void);
  97. /**
  98. * Finalize the physical presence settings: sofware PP is enabled, hardware PP
  99. * is disabled, and the lifetime lock is set. The TPM error code is returned.
  100. */
  101. uint32_t TlclFinalizePhysicalPresence(void);
  102. uint32_t TlclAssertPhysicalPresenceResult(void);
  103. /**
  104. * Turn off physical presence and locks it off until next reboot. The TPM
  105. * error code is returned.
  106. */
  107. uint32_t TlclLockPhysicalPresence(void);
  108. /**
  109. * Set the nvLocked bit. The TPM error code is returned.
  110. */
  111. uint32_t TlclSetNvLocked(void);
  112. /**
  113. * Return 1 if the TPM is owned, 0 otherwise.
  114. */
  115. int TlclIsOwned(void);
  116. /**
  117. * Issue a ForceClear. The TPM error code is returned.
  118. */
  119. uint32_t TlclForceClear(void);
  120. /**
  121. * Issue a PhysicalEnable. The TPM error code is returned.
  122. */
  123. uint32_t TlclSetEnable(void);
  124. /**
  125. * Issue a PhysicalDisable. The TPM error code is returned.
  126. */
  127. uint32_t TlclClearEnable(void);
  128. /**
  129. * Issue a SetDeactivated. Pass 0 to activate. Returns result code.
  130. */
  131. uint32_t TlclSetDeactivated(uint8_t flag);
  132. /**
  133. * Get flags of interest. Pointers for flags you aren't interested in may
  134. * be NULL. The TPM error code is returned.
  135. */
  136. uint32_t TlclGetFlags(uint8_t *disable, uint8_t *deactivated,
  137. uint8_t *nvlocked);
  138. /**
  139. * Set the bGlobalLock flag, which only a reboot can clear. The TPM error
  140. * code is returned.
  141. */
  142. uint32_t TlclSetGlobalLock(void);
  143. /**
  144. * Perform a TPM_Extend.
  145. */
  146. uint32_t TlclExtend(int pcr_num, const uint8_t *in_digest, uint8_t *out_digest);
  147. /**
  148. * Get the permission bits for the NVRAM space with |index|.
  149. */
  150. uint32_t TlclGetPermissions(uint32_t index, uint32_t *permissions);
  151. /**
  152. * Get the entire set of permanent flags.
  153. */
  154. uint32_t TlclGetPermanentFlags(TPM_PERMANENT_FLAGS *pflags);
  155. /**
  156. * Get the entire set of volatile (ST_CLEAR) flags.
  157. */
  158. uint32_t TlclGetSTClearFlags(TPM_STCLEAR_FLAGS *pflags);
  159. /**
  160. * Get the ownership flag. The TPM error code is returned.
  161. */
  162. uint32_t TlclGetOwnership(uint8_t *owned);
  163. /**
  164. * Request [length] bytes from TPM RNG to be stored in [data]. Actual number of
  165. * bytes read is stored in [size]. The TPM error code is returned.
  166. */
  167. uint32_t TlclGetRandom(uint8_t *data, uint32_t length, uint32_t *size);
  168. #endif /* TPM_LITE_TLCL_H_ */