Line | Count | Source (jump to first uncovered line) |
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_WriteLock_fp.h" |
10 | | #include "NV_spt_fp.h" |
11 | | // |
12 | | // |
13 | | // Error Returns Meaning |
14 | | // |
15 | | // TPM_RC_ATTRIBUTES neither TPMA_NV_WRITEDEFINE nor |
16 | | // TPMA_NV_WRITE_STCLEAR is SET in Index referenced by |
17 | | // nvIndex |
18 | | // TPM_RC_NV_AUTHORIZATION the authorization was valid but the authorizing entity (authHandle) is |
19 | | // not allowed to write to the Index referenced by nvIndex |
20 | | // |
21 | | TPM_RC |
22 | | TPM2_NV_WriteLock( |
23 | | NV_WriteLock_In *in // IN: input parameter list |
24 | | ) |
25 | 0 | { |
26 | 0 | TPM_RC result; |
27 | 0 | NV_INDEX nvIndex; |
28 | | |
29 | | // Input Validation: |
30 | | |
31 | | // Common write access checks, a TPM_RC_NV_AUTHORIZATION or TPM_RC_NV_LOCKED |
32 | | // error may be returned at this point |
33 | 0 | result = NvWriteAccessChecks(in->authHandle, in->nvIndex); |
34 | 0 | if(result != TPM_RC_SUCCESS) |
35 | 0 | { |
36 | 0 | if(result == TPM_RC_NV_AUTHORIZATION) |
37 | 0 | return TPM_RC_NV_AUTHORIZATION; |
38 | | // If write access failed because the index is already locked, then it is |
39 | | // no error. |
40 | 0 | return TPM_RC_SUCCESS; |
41 | 0 | } |
42 | | |
43 | | // Indexes in the virtual range are always locked. |
44 | 0 | if (_plat__NvGetHandleVirtualOffset(in->nvIndex)) |
45 | 0 | return TPM_RC_SUCCESS; |
46 | | |
47 | | // Get NV index info |
48 | 0 | NvGetIndexInfo(in->nvIndex, &nvIndex); |
49 | | |
50 | | // if neither TPMA_NV_WRITEDEFINE nor TPMA_NV_WRITE_STCLEAR is set, the index |
51 | | // can not be write-locked |
52 | 0 | if( nvIndex.publicArea.attributes.TPMA_NV_WRITEDEFINE == CLEAR |
53 | 0 | && nvIndex.publicArea.attributes.TPMA_NV_WRITE_STCLEAR == CLEAR) |
54 | 0 | return TPM_RC_ATTRIBUTES + RC_NV_WriteLock_nvIndex; |
55 | | |
56 | | // Internal Data Update |
57 | | |
58 | | // The command needs NV update. Check if NV is available. |
59 | | // A TPM_RC_NV_UNAVAILABLE or TPM_RC_NV_RATE error may be returned at |
60 | | // this point |
61 | 0 | result = NvIsAvailable(); |
62 | 0 | if(result != TPM_RC_SUCCESS) |
63 | 0 | return result; |
64 | | |
65 | | // Set the WRITELOCK attribute. |
66 | | // Note: if TPMA_NV_WRITELOCKED were already SET, then the write access check |
67 | | // above would have failed and this code isn't executed. |
68 | 0 | nvIndex.publicArea.attributes.TPMA_NV_WRITELOCKED = SET; |
69 | | |
70 | | // Write index info back |
71 | 0 | NvWriteIndexInfo(in->nvIndex, &nvIndex); |
72 | |
|
73 | 0 | return TPM_RC_SUCCESS; |
74 | 0 | } |