tss2_template.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. #ifndef TSS2_TEMPLATE_H
  3. #define TSS2_TEMPLATE_H
  4. #include <stdbool.h>
  5. #include <tss2/tss2_fapi.h>
  6. #include "lib/tpm2_options.h"
  7. #include "lib/tpm2_util.h"
  8. #define Fapi_Free(x) free(x)
  9. /**
  10. * An optional interface for tools to specify what options they support.
  11. * They are concatenated with main's options and passed to getopt_long.
  12. * @param opts
  13. * The callee can choose to set *opts to a tpm_options pointer allocated
  14. * via tpm2_options_new(). Setting *opts to NULL is not an error, and
  15. * Indicates that no options are specified by the tool.
  16. *
  17. * @return
  18. * True on success, false on error.
  19. */
  20. typedef bool (*tss2_tool_onstart_t)(tpm2_options **opts);
  21. /**
  22. * This is the main interface for tools, after tcti and fapi initialization
  23. * is performed.
  24. * @param fctx
  25. * The fapi api context.
  26. * @return
  27. * 0 on success
  28. * 1 on failure
  29. * -1 to show usage
  30. */
  31. typedef int (*tss2_tool_onrun_t)(FAPI_CONTEXT *fctx);
  32. /**
  33. * Called when the tool is exiting, useful for cleanup.
  34. */
  35. typedef void (*tss2_tool_onexit_t)(void);
  36. typedef struct {
  37. const char * name;
  38. tss2_tool_onstart_t onstart;
  39. tss2_tool_onrun_t onrun;
  40. tss2_tool_onexit_t onexit;
  41. } tss2_tool;
  42. void tss2_tool_register(const tss2_tool * tool);
  43. #define TSS2_TOOL_REGISTER(tool_name,tool_onstart,tool_onrun,tool_onexit) \
  44. static const tss2_tool tool = { \
  45. .name = tool_name, \
  46. .onstart = tool_onstart, \
  47. .onrun = tool_onrun, \
  48. .onexit = tool_onexit, \
  49. }; \
  50. static void \
  51. __attribute__((__constructor__)) \
  52. __attribute__((__used__)) \
  53. _tss2_tool_init(void) \
  54. { \
  55. tss2_tool_register(&tool); \
  56. }
  57. TSS2_RC policy_auth_callback(FAPI_CONTEXT*, char const*, char**, void*);
  58. int open_write_and_close(const char *path, bool overwrite, const void* output, size_t output_len);
  59. int open_read_and_close(const char *path, void **input, size_t *size);
  60. char* ask_for_password();
  61. void LOG_PERR(const char *func, TSS2_RC rc);
  62. void LOG_ERR(const char *format, ...);
  63. #endif /* TSS2_TEMPLATE_H */