2
0

tpm_util.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * TPM utility functions
  3. *
  4. * Copyright (c) 2010 - 2015 IBM Corporation
  5. * Authors:
  6. * Stefan Berger <stefanb@us.ibm.com>
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, see <http://www.gnu.org/licenses/>
  20. */
  21. #ifndef TPM_TPM_UTIL_H
  22. #define TPM_TPM_UTIL_H
  23. #include "sysemu/tpm.h"
  24. #include "qemu/bswap.h"
  25. void tpm_util_write_fatal_error_response(uint8_t *out, uint32_t out_len);
  26. bool tpm_util_is_selftest(const uint8_t *in, uint32_t in_len);
  27. int tpm_util_test_tpmdev(int tpm_fd, TPMVersion *tpm_version);
  28. static inline uint16_t tpm_cmd_get_tag(const void *b)
  29. {
  30. return lduw_be_p(b);
  31. }
  32. static inline void tpm_cmd_set_tag(void *b, uint16_t tag)
  33. {
  34. stw_be_p(b, tag);
  35. }
  36. static inline uint32_t tpm_cmd_get_size(const void *b)
  37. {
  38. return ldl_be_p(b + 2);
  39. }
  40. static inline void tpm_cmd_set_size(void *b, uint32_t size)
  41. {
  42. stl_be_p(b + 2, size);
  43. }
  44. static inline uint32_t tpm_cmd_get_ordinal(const void *b)
  45. {
  46. return ldl_be_p(b + 6);
  47. }
  48. static inline uint32_t tpm_cmd_get_errcode(const void *b)
  49. {
  50. return ldl_be_p(b + 6);
  51. }
  52. static inline void tpm_cmd_set_error(void *b, uint32_t error)
  53. {
  54. stl_be_p(b + 6, error);
  55. }
  56. int tpm_util_get_buffer_size(int tpm_fd, TPMVersion tpm_version,
  57. size_t *buffersize);
  58. #define DEFINE_PROP_TPMBE(_n, _s, _f) \
  59. DEFINE_PROP(_n, _s, _f, qdev_prop_tpm, TPMBackend *)
  60. typedef struct TPMSizedBuffer {
  61. uint32_t size;
  62. uint8_t *buffer;
  63. } TPMSizedBuffer;
  64. void tpm_sized_buffer_reset(TPMSizedBuffer *tsb);
  65. #endif /* TPM_TPM_UTIL_H */