tpm2_selftest.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. #include "log.h"
  3. #include "tpm2.h"
  4. #include "tpm2_tool.h"
  5. #include "tpm2_options.h"
  6. typedef struct tpm_selftest_ctx tpm_selftest_ctx;
  7. struct tpm_selftest_ctx {
  8. TPMI_YES_NO fulltest;
  9. };
  10. static tpm_selftest_ctx ctx;
  11. static bool on_option(char key, char *value) {
  12. UNUSED(value);
  13. switch (key) {
  14. case 'f':
  15. ctx.fulltest = TPM2_YES;
  16. break;
  17. default:
  18. LOG_ERR("Invalid option.");
  19. return false;
  20. }
  21. return true;
  22. }
  23. static bool tpm2_tool_onstart(tpm2_options **opts) {
  24. static const struct option topts[] = {
  25. { "fulltest", no_argument, NULL, 'f' }
  26. };
  27. ctx.fulltest = TPM2_NO;
  28. *opts = tpm2_options_new("f", ARRAY_LEN(topts), topts, on_option, NULL, 0);
  29. return *opts != NULL;
  30. }
  31. static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
  32. UNUSED(flags);
  33. return tpm2_selftest(ectx, ctx.fulltest);
  34. }
  35. // Register this tool with tpm2_tool.c
  36. TPM2_TOOL_REGISTER("selftest", tpm2_tool_onstart, tpm2_tool_onrun, NULL, NULL)