Home | History | Annotate | Download | only in tpm2
      1 // This file was extracted from the TCG Published
      2 // Trusted Platform Module Library
      3 // Part 3: Commands
      4 // Family "2.0"
      5 // Level 00 Revision 01.16
      6 // October 30, 2014
      7 
      8 #include "InternalRoutines.h"
      9 #include "NV_Read_fp.h"
     10 #include "NV_spt_fp.h"
     11 //
     12 //
     13 //     Error Returns                     Meaning
     14 //
     15 //     TPM_RC_NV_AUTHORIZATION           the authorization was valid but the authorizing entity (authHandle) is
     16 //                                       not allowed to read from the Index referenced by nvIndex
     17 //     TPM_RC_NV_LOCKED                  the Index referenced by nvIndex is read locked
     18 //     TPM_RC_NV_RANGE                   read range defined by size and offset is outside the range of the
     19 //                                       Index referenced by nvIndex
     20 //     TPM_RC_NV_UNINITIALIZED           the Index referenced by nvIndex has not been initialized (written)
     21 //
     22 TPM_RC
     23 TPM2_NV_Read(
     24    NV_Read_In        *in,                 // IN: input parameter list
     25    NV_Read_Out       *out                 // OUT: output parameter list
     26    )
     27 {
     28    NV_INDEX          nvIndex;
     29    TPM_RC            result;
     30 
     31 // Input Validation
     32 
     33    // Get NV index info
     34    NvGetIndexInfo(in->nvIndex, &nvIndex);
     35 
     36    // Common read access checks. NvReadAccessChecks() returns
     37    // TPM_RC_NV_AUTHORIZATION, TPM_RC_NV_LOCKED, or TPM_RC_NV_UNINITIALIZED
     38    // error may be returned at this point
     39    result = NvReadAccessChecks(in->authHandle, in->nvIndex);
     40    if(result != TPM_RC_SUCCESS)
     41        return result;
     42 
     43    // Too much data
     44    if((in->size + in->offset) > nvIndex.publicArea.dataSize)
     45        return TPM_RC_NV_RANGE;
     46 
     47 // Command Output
     48 
     49    // Set the return size
     50    out->data.t.size = in->size;
     51    // Perform the read
     52    NvGetIndexData(in->nvIndex, &nvIndex, in->offset, in->size, out->data.t.buffer);
     53 
     54    return TPM_RC_SUCCESS;
     55 }
     56