tpm.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Copyright (c) 2013 The Chromium OS Authors.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #ifndef __TPM_H
  23. #define __TPM_H
  24. #include <tis.h>
  25. /*
  26. * Here is a partial implementation of TPM commands. Please consult TCG Main
  27. * Specification for definitions of TPM commands.
  28. */
  29. enum tpm_startup_type {
  30. TPM_ST_CLEAR = 0x0001,
  31. TPM_ST_STATE = 0x0002,
  32. TPM_ST_DEACTIVATED = 0x0003,
  33. };
  34. enum tpm_physical_presence {
  35. TPM_PHYSICAL_PRESENCE_HW_DISABLE = 0x0200,
  36. TPM_PHYSICAL_PRESENCE_CMD_DISABLE = 0x0100,
  37. TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK = 0x0080,
  38. TPM_PHYSICAL_PRESENCE_HW_ENABLE = 0x0040,
  39. TPM_PHYSICAL_PRESENCE_CMD_ENABLE = 0x0020,
  40. TPM_PHYSICAL_PRESENCE_NOTPRESENT = 0x0010,
  41. TPM_PHYSICAL_PRESENCE_PRESENT = 0x0008,
  42. TPM_PHYSICAL_PRESENCE_LOCK = 0x0004,
  43. };
  44. enum tpm_nv_index {
  45. TPM_NV_INDEX_LOCK = 0xffffffff,
  46. TPM_NV_INDEX_0 = 0x00000000,
  47. TPM_NV_INDEX_DIR = 0x10000001,
  48. };
  49. /**
  50. * Initialize TPM device. It must be called before any TPM commands.
  51. *
  52. * @return 0 on success, non-0 on error.
  53. */
  54. uint32_t tpm_init(void);
  55. /**
  56. * Issue a TPM_Startup command.
  57. *
  58. * @param mode TPM startup mode
  59. * @return return code of the operation
  60. */
  61. uint32_t tpm_startup(enum tpm_startup_type mode);
  62. /**
  63. * Issue a TPM_SelfTestFull command.
  64. *
  65. * @return return code of the operation
  66. */
  67. uint32_t tpm_self_test_full(void);
  68. /**
  69. * Issue a TPM_ContinueSelfTest command.
  70. *
  71. * @return return code of the operation
  72. */
  73. uint32_t tpm_continue_self_test(void);
  74. /**
  75. * Issue a TPM_NV_DefineSpace command. The implementation is limited
  76. * to specify TPM_NV_ATTRIBUTES and size of the area. The area index
  77. * could be one of the special value listed in enum tpm_nv_index.
  78. *
  79. * @param index index of the area
  80. * @param perm TPM_NV_ATTRIBUTES of the area
  81. * @param size size of the area
  82. * @return return code of the operation
  83. */
  84. uint32_t tpm_nv_define_space(uint32_t index, uint32_t perm, uint32_t size);
  85. /**
  86. * Issue a TPM_NV_ReadValue command. This implementation is limited
  87. * to read the area from offset 0. The area index could be one of
  88. * the special value listed in enum tpm_nv_index.
  89. *
  90. * @param index index of the area
  91. * @param data output buffer of the area contents
  92. * @param count size of output buffer
  93. * @return return code of the operation
  94. */
  95. uint32_t tpm_nv_read_value(uint32_t index, void *data, uint32_t count);
  96. /**
  97. * Issue a TPM_NV_WriteValue command. This implementation is limited
  98. * to write the area from offset 0. The area index could be one of
  99. * the special value listed in enum tpm_nv_index.
  100. *
  101. * @param index index of the area
  102. * @param data input buffer to be wrote to the area
  103. * @param length length of data bytes of input buffer
  104. * @return return code of the operation
  105. */
  106. uint32_t tpm_nv_write_value(uint32_t index, const void *data, uint32_t length);
  107. /**
  108. * Issue a TPM_Extend command.
  109. *
  110. * @param index index of the PCR
  111. * @param in_digest 160-bit value representing the event to be
  112. * recorded
  113. * @param out_digest 160-bit PCR value after execution of the
  114. * command
  115. * @return return code of the operation
  116. */
  117. uint32_t tpm_extend(uint32_t index, const void *in_digest, void *out_digest);
  118. /**
  119. * Issue a TPM_PCRRead command.
  120. *
  121. * @param index index of the PCR
  122. * @param data output buffer for contents of the named PCR
  123. * @param count size of output buffer
  124. * @return return code of the operation
  125. */
  126. uint32_t tpm_pcr_read(uint32_t index, void *data, size_t count);
  127. /**
  128. * Issue a TSC_PhysicalPresence command. TPM physical presence flag
  129. * is bit-wise OR'ed of flags listed in enum tpm_physical_presence.
  130. *
  131. * @param presence TPM physical presence flag
  132. * @return return code of the operation
  133. */
  134. uint32_t tpm_tsc_physical_presence(uint16_t presence);
  135. /**
  136. * Issue a TPM_ReadPubek command.
  137. *
  138. * @param data output buffer for the public endorsement key
  139. * @param count size of ouput buffer
  140. * @return return code of the operation
  141. */
  142. uint32_t tpm_read_pubek(void *data, size_t count);
  143. /**
  144. * Issue a TPM_ForceClear command.
  145. *
  146. * @return return code of the operation
  147. */
  148. uint32_t tpm_force_clear(void);
  149. /**
  150. * Issue a TPM_PhysicalEnable command.
  151. *
  152. * @return return code of the operation
  153. */
  154. uint32_t tpm_physical_enable(void);
  155. /**
  156. * Issue a TPM_PhysicalDisable command.
  157. *
  158. * @return return code of the operation
  159. */
  160. uint32_t tpm_physical_disable(void);
  161. /**
  162. * Issue a TPM_PhysicalSetDeactivated command.
  163. *
  164. * @param state boolean state of the deactivated flag
  165. * @return return code of the operation
  166. */
  167. uint32_t tpm_physical_set_deactivated(uint8_t state);
  168. /**
  169. * Issue a TPM_GetCapability command. This implementation is limited
  170. * to query sub_cap index that is 4-byte wide.
  171. *
  172. * @param cap_area partition of capabilities
  173. * @param sub_cap further definition of capability, which is
  174. * limited to be 4-byte wide
  175. * @param cap output buffer for capability information
  176. * @param count size of ouput buffer
  177. * @return return code of the operation
  178. */
  179. uint32_t tpm_get_capability(uint32_t cap_area, uint32_t sub_cap,
  180. void *cap, size_t count);
  181. #endif /* __TPM_H */