blob: 144e935b92d2b25ff9382b5f1e7ce6c6e331475d [file] [log] [blame]
Vadim Bendebury56797522015-05-20 10:32:25 -07001// 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_UndefineSpace_fp.h"
10//
11//
12// Error Returns Meaning
13//
14// TPM_RC_ATTRIBUTES TPMA_NV_POLICY_DELETE is SET in the Index referenced by
15// nvIndex so this command may not be used to delete this Index (see
16// TPM2_NV_UndefineSpaceSpecial())
17// TPM_RC_NV_AUTHORIZATION attempt to use ownerAuth to delete an index created by the platform
18//
19TPM_RC
20TPM2_NV_UndefineSpace(
21 NV_UndefineSpace_In *in // IN: input parameter list
22 )
23{
24 TPM_RC result;
25 NV_INDEX nvIndex;
26
27 // The command needs NV update. Check if NV is available.
28 // A TPM_RC_NV_UNAVAILABLE or TPM_RC_NV_RATE error may be returned at
29 // this point
30 result = NvIsAvailable();
31 if(result != TPM_RC_SUCCESS) return result;
32
Louis Collard5cb743a2018-06-26 20:07:49 +080033 // Indexes in the virtual range cannot be undefined.
34 if (_plat__NvGetHandleVirtualOffset(in->nvIndex))
35 return TPM_RC_NV_AUTHORIZATION;
36
Vadim Bendebury56797522015-05-20 10:32:25 -070037// Input Validation
38
39 // Get NV index info
40 NvGetIndexInfo(in->nvIndex, &nvIndex);
41
42 // This command can't be used to delete an index with TPMA_NV_POLICY_DELETE SET
43 if(SET == nvIndex.publicArea.attributes.TPMA_NV_POLICY_DELETE)
44 return TPM_RC_ATTRIBUTES + RC_NV_UndefineSpace_nvIndex;
45
46 // The owner may only delete an index that was defined with ownerAuth. The
47 // platform may delete an index that was created with either auth.
48 if( in->authHandle == TPM_RH_OWNER
49 && nvIndex.publicArea.attributes.TPMA_NV_PLATFORMCREATE == SET)
50 return TPM_RC_NV_AUTHORIZATION;
51
52// Internal Data Update
53
54 // Call implementation dependent internal routine to delete NV index
55 NvDeleteEntity(in->nvIndex);
56
57 return TPM_RC_SUCCESS;
58}