tpm2_marshaling.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2016 The Chromium OS Authors. All rights reserved.
  3. * Use of this source code is governed by a BSD-style license that can be
  4. * found in the LICENSE file.
  5. */
  6. #ifndef __SRC_LIB_TPM2_MARSHALING_H
  7. #define __SRC_LIB_TPM2_MARSHALING_H
  8. #include "tss_constants.h"
  9. /* The below functions are used to serialize/deserialize TPM2 commands. */
  10. /**
  11. * tpm_marshal_command
  12. *
  13. * Given a structure containing a TPM2 command, serialize the structure for
  14. * sending it to the TPM.
  15. *
  16. * @command: code of the TPM2 command to marshal
  17. * @tpm_command_body: a pointer to the command specific structure
  18. * @buffer: buffer where command is marshaled to
  19. * @buffer_size: size of the buffer
  20. *
  21. * Returns number of bytes placed in the buffer, or -1 on error.
  22. *
  23. */
  24. int tpm_marshal_command(TPM_CC command, void *tpm_command_body,
  25. void *buffer, int buffer_size);
  26. /**
  27. * tpm_unmarshal_response
  28. *
  29. * Given a buffer received from the TPM in response to a certain command,
  30. * deserialize the buffer into the expeced response structure.
  31. *
  32. * struct tpm2_response is a union of all possible responses.
  33. *
  34. * @command: code of the TPM2 command for which a response is unmarshaled
  35. * @response_body: buffer containing the serialized response.
  36. * @response_size: number of bytes in the buffer containing response
  37. *
  38. * Returns a pointer to the deserialized response or NULL in case of
  39. * unmarshaling problems.
  40. */
  41. struct tpm2_response *tpm_unmarshal_response(TPM_CC command,
  42. void *response_body,
  43. int response_size);
  44. /**
  45. * tpm_get_packet_size
  46. *
  47. * @packet: pointer to the start of the command or response packet.
  48. *
  49. * Returns the size of the tpm packet.
  50. */
  51. uint32_t tpm_get_packet_size(const uint8_t *packet);
  52. /**
  53. * tpm_get_packet_response_code
  54. *
  55. * @packet: pointer to the start of the response packet.
  56. *
  57. * Returns the response code.
  58. */
  59. uint32_t tpm_get_packet_response_code(const uint8_t *packet);
  60. /**
  61. * tpm_set_ph_disabled
  62. *
  63. * Sets the flag that indicates if platform hierarchy is disabled.
  64. * Certain commands, like NV_Read, may need to use different
  65. * authorization if platform hierarchy is disabled.
  66. *
  67. * @flag: 1 if platform hierarchy is disabled, 0 otherwise
  68. */
  69. void tpm_set_ph_disabled(int flag);
  70. /**
  71. * tpm_is_ph_disabled
  72. *
  73. * Gets the flag that indicates if platform hierarchy is disabled.
  74. * Certain commands, like NV_Read, may need to use different
  75. * authorization if platform hierarchy is disabled.
  76. *
  77. * Returns 1 if platform hierarchy is disabled, 0 otherwise
  78. */
  79. int tpm_is_ph_disabled(void);
  80. #endif // __SRC_LIB_TPM2_MARSHALING_H