tss2_nvincrement.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. #include <stdio.h>
  3. #include "tools/fapi/tss2_template.h"
  4. /* Variable used to store passed command line parameter */
  5. static char const *nvPath;
  6. /* Parse command line parameters */
  7. static bool on_option(char key, char *value) {
  8. switch (key) {
  9. case 'p':
  10. nvPath = value;
  11. break;
  12. }
  13. return true;
  14. }
  15. /* Define possible command line parameters */
  16. static bool tss2_tool_onstart(tpm2_options **opts) {
  17. struct option topts[] = {
  18. {"nvPath", required_argument, NULL, 'p'}
  19. };
  20. return (*opts = tpm2_options_new ("p:", ARRAY_LEN(topts), topts,
  21. on_option, NULL, 0)) != NULL;
  22. }
  23. /* Execute specific tool */
  24. static int tss2_tool_onrun (FAPI_CONTEXT *fctx) {
  25. /* Check availability of required parameters */
  26. if (!nvPath) {
  27. fprintf (stderr, "No path to the NV provided, use --nvPath\n");
  28. return -1;
  29. }
  30. /* Execute FAPI command with passed arguments */
  31. TSS2_RC r = Fapi_NvIncrement(fctx, nvPath);
  32. if (r != TSS2_RC_SUCCESS){
  33. LOG_PERR("Fapi_NV_Increment", r);
  34. return 1;
  35. }
  36. return 0;
  37. }
  38. TSS2_TOOL_REGISTER("nvincrement", tss2_tool_onstart, tss2_tool_onrun, NULL)