Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TPM_RC decode tool #82

Merged
merged 3 commits into from
Jul 13, 2016
Merged

TPM_RC decode tool #82

merged 3 commits into from
Jul 13, 2016

Conversation

flihp
Copy link
Contributor

@flihp flihp commented Jul 13, 2016

This replaces #78. It includes 3 commits, each adding a component of the TPM_RC decode stuff.

Use cmocka to unit test it. Add .gitignore rules to ignore test logs.

Signed-off-by: Philip Tricca <flihp@twobit.us>
This includes functions to look them up as well as unit tests to ensure
the lookup functions work as expected.

Signed-off-by: Philip Tricca <flihp@twobit.us>
Basic usage is extremely simple and documented in the -h/--help option.
It expects a single 32bit TPM_RC as a positional parameter. This number
is parsed using the convenience functions in the rc-decode.h header.
This tool then generates human readable output describing each component
of the TPM_RC. This requires a few lookups in the tables from
rc-decode.c, accessed using the helper functions.

The algorithm is roughly:
  Extract the TSS layer / level indicator
  if TCTI | SAPI error
    print layer data to stdout
    lookup string mapping for the error code
    print error code data to stdout
  else if PART2 | TPM error
    if error code is in format zero
      if error code is vendor defined
        return error
      else if error code is a warning
        lookup string mapping for warning code
        print warning code data to stdout
      else if error code is an error
        lookup string mapping for error code
        print error code data to stdout
      else if error code is a TPM 1.2 format
        print error: 1.2 TPM_RCs aren't supported
        return error
      else
        print error: unknown TPM_RC format
        return error
      endif
    else if error code is in format one
      lookup string mapping for the error code
      print error code data to stdout
      if error code has parameter data
        lookup string mapping for parameter code
        print parameter code data to stdout
      else if error code has handle data
        lookup string mapping for handle code
        print handle code data to stdout
      else if error code has session data
        lookup string mapping for session code
        print session code data to stdout
      endif
    endif
  endif

The output format for data is very simple. Each component of
the TPM_RC is preceded by a line identifying the component.
Data about the layer producing the error is preceded by:
'error layer' followed by a new line.

The data in the field is then decoded and the hex value, a
string representation of the identifier and then a string
describing the error. These 3 items are printed each on their
own line and indented 2 spaces. An example makes this more
clear:

TSS2_SYS_PART2_RC_LEVEL + TSS2_SYS_PART2_RC_LEVEL = 0x90100
$ src/tpm2_rc_decode 0x90100
error layer
  hex: 0x90000
  identifier: TSS2_SYS_PART2_RC_LEVEL
  description: Error from the SAPI duplicating TPM error check
format 0 error code
  hex: 0x00
  name: TPM_RC_INITIALIZE
  description: TPM not initialized

TPM_FMT1 + TPM_RC_P + TPM_RC_MFG + TPM_RC_3 = 0x3c8
error layer
  hex: 0x0
  identifier: TSS2_TPM_ERROR_LEVEL
  description: Error produced by the TPM
format 1 error code
  hex: 0x08
  identifier: TPM_RC_MGF
  description: mask generation function not supported
parameter
  hex: 0x300
  identifier:  TPM_RC_3
  description:  (null)

Signed-off-by: Philip Tricca <philip.b.tricca@intel.com>
@gwei3 gwei3 merged commit 723e0cc into tpm2-software:master Jul 13, 2016
@gwei3 gwei3 mentioned this pull request Jul 13, 2016
@flihp flihp deleted the rc-decode-tool branch February 8, 2017 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants