tss2_provision.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. #include <stdio.h>
  3. #include "tools/fapi/tss2_template.h"
  4. /* Context struct used to store passed commandline parameters */
  5. static struct cxt {
  6. char *authValueEh;
  7. char *authValueSh;
  8. char *authValueLockout;
  9. } ctx;
  10. /* Parse commandline parameters */
  11. static bool on_option(char key, char *value) {
  12. switch (key) {
  13. case 'E':
  14. ctx.authValueEh = value;
  15. break;
  16. case 'S':
  17. ctx.authValueSh = value;
  18. break;
  19. case 'L':
  20. ctx.authValueLockout = value;
  21. break;
  22. }
  23. return true;
  24. }
  25. /* Define possible commandline parameters */
  26. static bool tss2_tool_onstart(tpm2_options **opts) {
  27. struct option topts[] = {
  28. {"authValueEh", required_argument, NULL, 'E'},
  29. {"authValueSh", required_argument, NULL, 'S'},
  30. {"authValueLockout", required_argument, NULL, 'L'},
  31. };
  32. return (*opts = tpm2_options_new ("E:S:L",
  33. ARRAY_LEN(topts), topts, on_option, NULL, 0)) != NULL;
  34. }
  35. /* Execute specific tool */
  36. static int tss2_tool_onrun (FAPI_CONTEXT *fctx) {
  37. /* Execute FAPI command with passed arguments */
  38. TSS2_RC r = Fapi_Provision (fctx, ctx.authValueEh, ctx.authValueSh,
  39. ctx.authValueLockout);
  40. if (r != TSS2_RC_SUCCESS){
  41. LOG_PERR ("Fapi_Provision", r);
  42. return 1;
  43. }
  44. return 0;
  45. }
  46. TSS2_TOOL_REGISTER("provision", tss2_tool_onstart, tss2_tool_onrun, NULL)