blob: 7d65dfe00ecf294c518e8898eadd0cfda383db64 [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_Write_fp.h"
10#include "NV_spt_fp.h"
11//
12//
13// Error Returns Meaning
14//
15// TPM_RC_ATTRIBUTES Index referenced by nvIndex has either TPMA_NV_BITS,
16// TPMA_NV_COUNTER, or TPMA_NV_EVENT attribute SET
17// TPM_RC_NV_AUTHORIZATION the authorization was valid but the authorizing entity (authHandle) is
18// not allowed to write to the Index referenced by nvIndex
19// TPM_RC_NV_LOCKED Index referenced by nvIndex is write locked
20// TPM_RC_NV_RANGE if TPMA_NV_WRITEALL is SET then the write is not the size of the
21// Index referenced by nvIndex; otherwise, the write extends beyond the
22// limits of the Index
23//
24TPM_RC
25TPM2_NV_Write(
26 NV_Write_In *in // IN: input parameter list
27 )
28{
29 NV_INDEX nvIndex;
30 TPM_RC result;
31
32// Input Validation
33
34 // Get NV index info
35 NvGetIndexInfo(in->nvIndex, &nvIndex);
36
37 // common access checks. NvWrtieAccessChecks() may return
38 // TPM_RC_NV_AUTHORIZATION or TPM_RC_NV_LOCKED
39 result = NvWriteAccessChecks(in->authHandle, in->nvIndex);
40 if(result != TPM_RC_SUCCESS)
41 return result;
42
Louis Collard5cb743a2018-06-26 20:07:49 +080043 // Indexes in the virtual range cannot be written.
44 if (_plat__NvGetHandleVirtualOffset(in->nvIndex))
45 return TPM_RC_NV_LOCKED;
46
Vadim Bendebury56797522015-05-20 10:32:25 -070047 // Bits index, extend index or counter index may not be updated by
48 // TPM2_NV_Write
49 if( nvIndex.publicArea.attributes.TPMA_NV_COUNTER == SET
50 || nvIndex.publicArea.attributes.TPMA_NV_BITS == SET
51 || nvIndex.publicArea.attributes.TPMA_NV_EXTEND == SET)
52 return TPM_RC_ATTRIBUTES;
53
54 // Too much data
55 if((in->data.t.size + in->offset) > nvIndex.publicArea.dataSize)
56 return TPM_RC_NV_RANGE;
57
58 // If this index requires a full sized write, make sure that input range is
59 // full sized
60 if( nvIndex.publicArea.attributes.TPMA_NV_WRITEALL == SET
61 && in->data.t.size < nvIndex.publicArea.dataSize)
62 return TPM_RC_NV_RANGE;
63
64// Internal Data Update
65
66 // Perform the write. This called routine will SET the TPMA_NV_WRITTEN
67 // attribute if it has not already been SET. If NV isn't available, an error
68 // will be returned.
Namyoon Woo96cf1e92020-01-28 17:47:22 -080069 result = NvWriteIndexData(in->nvIndex, &nvIndex, in->offset,
70 in->data.t.size, in->data.t.buffer);
71
72 _plat__NvInformIndexDataChanged(in->nvIndex);
73
74 return result;
Vadim Bendebury56797522015-05-20 10:32:25 -070075
76}