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_UndefineSpaceSpecial_fp.h"
10 //
11 //
12 //     Error Returns                    Meaning
13 //
14 //     TPM_RC_ATTRIBUTES                TPMA_NV_POLICY_DELETE is not SET in the Index referenced by
15 //                                      nvIndex
16 //
17 TPM_RC
TPM2_NV_UndefineSpaceSpecial(NV_UndefineSpaceSpecial_In * in)18 TPM2_NV_UndefineSpaceSpecial(
19    NV_UndefineSpaceSpecial_In      *in              // IN: input parameter list
20    )
21 {
22    TPM_RC            result;
23    NV_INDEX          nvIndex;
24 
25    // The command needs NV update. Check if NV is available.
26    // A TPM_RC_NV_UNAVAILABLE or TPM_RC_NV_RATE error may be returned at
27    // this point
28    result = NvIsAvailable();
29    if(result != TPM_RC_SUCCESS)
30        return result;
31 
32 // Input Validation
33 
34    // Get NV index info
35    NvGetIndexInfo(in->nvIndex, &nvIndex);
36 
37    // This operation only applies when the TPMA_NV_POLICY_DELETE attribute is SET
38    if(CLEAR == nvIndex.publicArea.attributes.TPMA_NV_POLICY_DELETE)
39        return TPM_RC_ATTRIBUTES + RC_NV_UndefineSpaceSpecial_nvIndex;
40 
41 // Internal Data Update
42 
43    // Call implementation dependent internal routine to delete NV index
44    NvDeleteEntity(in->nvIndex);
45 
46    return TPM_RC_SUCCESS;
47 }
48