/src/libtpms/src/tpm2/CapabilityCommands.c
Line | Count | Source |
1 | | /********************************************************************************/ |
2 | | /* */ |
3 | | /* Capability Commands */ |
4 | | /* Written by Ken Goldman */ |
5 | | /* IBM Thomas J. Watson Research Center */ |
6 | | /* */ |
7 | | /* Licenses and Notices */ |
8 | | /* */ |
9 | | /* 1. Copyright Licenses: */ |
10 | | /* */ |
11 | | /* - Trusted Computing Group (TCG) grants to the user of the source code in */ |
12 | | /* this specification (the "Source Code") a worldwide, irrevocable, */ |
13 | | /* nonexclusive, royalty free, copyright license to reproduce, create */ |
14 | | /* derivative works, distribute, display and perform the Source Code and */ |
15 | | /* derivative works thereof, and to grant others the rights granted herein. */ |
16 | | /* */ |
17 | | /* - The TCG grants to the user of the other parts of the specification */ |
18 | | /* (other than the Source Code) the rights to reproduce, distribute, */ |
19 | | /* display, and perform the specification solely for the purpose of */ |
20 | | /* developing products based on such documents. */ |
21 | | /* */ |
22 | | /* 2. Source Code Distribution Conditions: */ |
23 | | /* */ |
24 | | /* - Redistributions of Source Code must retain the above copyright licenses, */ |
25 | | /* this list of conditions and the following disclaimers. */ |
26 | | /* */ |
27 | | /* - Redistributions in binary form must reproduce the above copyright */ |
28 | | /* licenses, this list of conditions and the following disclaimers in the */ |
29 | | /* documentation and/or other materials provided with the distribution. */ |
30 | | /* */ |
31 | | /* 3. Disclaimers: */ |
32 | | /* */ |
33 | | /* - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */ |
34 | | /* LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */ |
35 | | /* RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */ |
36 | | /* THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE. */ |
37 | | /* Contact TCG Administration (admin@trustedcomputinggroup.org) for */ |
38 | | /* information on specification licensing rights available through TCG */ |
39 | | /* membership agreements. */ |
40 | | /* */ |
41 | | /* - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED */ |
42 | | /* WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR */ |
43 | | /* FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR */ |
44 | | /* NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY */ |
45 | | /* OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE. */ |
46 | | /* */ |
47 | | /* - Without limitation, TCG and its members and licensors disclaim all */ |
48 | | /* liability, including liability for infringement of any proprietary */ |
49 | | /* rights, relating to use of information in this specification and to the */ |
50 | | /* implementation of this specification, and TCG disclaims all liability for */ |
51 | | /* cost of procurement of substitute goods or services, lost profits, loss */ |
52 | | /* of use, loss of data or any incidental, consequential, direct, indirect, */ |
53 | | /* or special damages, whether under contract, tort, warranty or otherwise, */ |
54 | | /* arising in any way out of use or reliance upon this specification or any */ |
55 | | /* information herein. */ |
56 | | /* */ |
57 | | /* (c) Copyright IBM Corp. and others, 2016 - 2023 */ |
58 | | /* */ |
59 | | /********************************************************************************/ |
60 | | |
61 | | #include "Tpm.h" |
62 | | #include "GetCapability_fp.h" |
63 | | #if CC_GetCapability // Conditional expansion of this file |
64 | | TPM_RC |
65 | | TPM2_GetCapability( |
66 | | GetCapability_In *in, // IN: input parameter list |
67 | | GetCapability_Out *out // OUT: output parameter list |
68 | | ) |
69 | 1.21k | { |
70 | 1.21k | TPMU_CAPABILITIES *data = &out->capabilityData.data; |
71 | | // Command Output |
72 | | // Set output capability type the same as input type |
73 | 1.21k | out->capabilityData.capability = in->capability; |
74 | 1.21k | switch(in->capability) |
75 | 1.21k | { |
76 | 53 | case TPM_CAP_ALGS: |
77 | 53 | out->moreData = AlgorithmCapGetImplemented((TPM_ALG_ID)in->property, |
78 | 53 | in->propertyCount, |
79 | 53 | &data->algorithms); |
80 | 53 | break; |
81 | 390 | case TPM_CAP_HANDLES: |
82 | 390 | switch(HandleGetType((TPM_HANDLE)in->property)) |
83 | 390 | { |
84 | 26 | case TPM_HT_TRANSIENT: |
85 | | // Get list of handles of loaded transient objects |
86 | 26 | out->moreData = ObjectCapGetLoaded((TPM_HANDLE)in->property, |
87 | 26 | in->propertyCount, |
88 | 26 | &data->handles); |
89 | 26 | break; |
90 | 53 | case TPM_HT_PERSISTENT: |
91 | | // Get list of handles of persistent objects |
92 | 53 | out->moreData = NvCapGetPersistent((TPM_HANDLE)in->property, |
93 | 53 | in->propertyCount, |
94 | 53 | &data->handles); |
95 | 53 | break; |
96 | 31 | case TPM_HT_NV_INDEX: |
97 | | // Get list of defined NV index |
98 | 31 | out->moreData = NvCapGetIndex((TPM_HANDLE)in->property, |
99 | 31 | in->propertyCount, |
100 | 31 | &data->handles); |
101 | 31 | break; |
102 | 53 | case TPM_HT_LOADED_SESSION: |
103 | | // Get list of handles of loaded sessions |
104 | 53 | out->moreData = SessionCapGetLoaded((TPM_HANDLE)in->property, |
105 | 53 | in->propertyCount, |
106 | 53 | &data->handles); |
107 | 53 | break; |
108 | 0 | #ifdef TPM_HT_SAVED_SESSION |
109 | 42 | case TPM_HT_SAVED_SESSION: |
110 | | #else |
111 | | case TPM_HT_ACTIVE_SESSION: |
112 | | #endif |
113 | | // Get list of handles of |
114 | 42 | out->moreData = SessionCapGetSaved((TPM_HANDLE)in->property, |
115 | 42 | in->propertyCount, |
116 | 42 | &data->handles); |
117 | 42 | break; |
118 | 50 | case TPM_HT_PCR: |
119 | | // Get list of handles of PCR |
120 | 50 | out->moreData = PCRCapGetHandles((TPM_HANDLE)in->property, |
121 | 50 | in->propertyCount, |
122 | 50 | &data->handles); |
123 | 50 | break; |
124 | 134 | case TPM_HT_PERMANENT: |
125 | | // Get list of permanent handles |
126 | 134 | out->moreData = PermanentCapGetHandles((TPM_HANDLE)in->property, |
127 | 134 | in->propertyCount, |
128 | 134 | &data->handles); |
129 | 134 | break; |
130 | 1 | default: |
131 | | // Unsupported input handle type |
132 | 1 | return TPM_RCS_HANDLE + RC_GetCapability_property; |
133 | 0 | break; |
134 | 390 | } |
135 | 389 | break; |
136 | 389 | case TPM_CAP_COMMANDS: |
137 | 72 | out->moreData = CommandCapGetCCList((TPM_CC)in->property, |
138 | 72 | in->propertyCount, |
139 | 72 | &data->command); |
140 | 72 | break; |
141 | 74 | case TPM_CAP_PP_COMMANDS: |
142 | 74 | out->moreData = PhysicalPresenceCapGetCCList((TPM_CC)in->property, |
143 | 74 | in->propertyCount, |
144 | 74 | &data->ppCommands); |
145 | 74 | break; |
146 | 64 | case TPM_CAP_AUDIT_COMMANDS: |
147 | 64 | out->moreData = CommandAuditCapGetCCList((TPM_CC)in->property, |
148 | 64 | in->propertyCount, |
149 | 64 | &data->auditCommands); |
150 | 64 | break; |
151 | 89 | case TPM_CAP_PCRS: |
152 | | // Input property must be 0 |
153 | 89 | if(in->property != 0) |
154 | 40 | return TPM_RCS_VALUE + RC_GetCapability_property; |
155 | 49 | out->moreData = PCRCapGetAllocation(in->propertyCount, |
156 | 49 | &data->assignedPCR); |
157 | 49 | break; |
158 | 81 | case TPM_CAP_PCR_PROPERTIES: |
159 | 81 | out->moreData = PCRCapGetProperties((TPM_PT_PCR)in->property, |
160 | 81 | in->propertyCount, |
161 | 81 | &data->pcrProperties); |
162 | 81 | break; |
163 | 101 | case TPM_CAP_TPM_PROPERTIES: |
164 | 101 | out->moreData = TPMCapGetProperties((TPM_PT)in->property, |
165 | 101 | in->propertyCount, |
166 | 101 | &data->tpmProperties); |
167 | 101 | break; |
168 | 0 | #if ALG_ECC |
169 | 56 | case TPM_CAP_ECC_CURVES: |
170 | 56 | out->moreData = CryptCapGetECCCurve((TPM_ECC_CURVE)in->property, |
171 | 56 | in->propertyCount, |
172 | 56 | &data->eccCurves); |
173 | 56 | break; |
174 | 0 | #endif // TPM_ALG_ECC |
175 | 121 | case TPM_CAP_AUTH_POLICIES: |
176 | 121 | if(HandleGetType((TPM_HANDLE)in->property) != TPM_HT_PERMANENT) |
177 | 9 | return TPM_RCS_VALUE + RC_GetCapability_property; |
178 | 112 | out->moreData = PermanentHandleGetPolicy((TPM_HANDLE)in->property, |
179 | 112 | in->propertyCount, |
180 | 112 | &data->authPolicies); |
181 | 112 | break; |
182 | 111 | case TPM_CAP_ACT: |
183 | 111 | if(((TPM_RH)in->property < TPM_RH_ACT_0) |
184 | 85 | || ((TPM_RH)in->property > TPM_RH_ACT_F)) |
185 | 57 | return TPM_RCS_VALUE + RC_GetCapability_property; |
186 | 54 | out->moreData = ActGetCapabilityData((TPM_HANDLE)in->property, |
187 | 54 | in->propertyCount, |
188 | 54 | &data->actData); |
189 | 54 | break; |
190 | | # if SEC_CHANNEL_SUPPORT |
191 | | case TPM_CAP_PUB_KEYS: |
192 | | // This reference implementation supports only a single TPM SPDM public key |
193 | | if((TPM_PUB_KEY)in->property != TPM_PUB_KEY_TPM_SPDM_00) |
194 | | return TPM_RCS_VALUE + RC_GetCapability_property; |
195 | | out->moreData = SpdmCapGetTpmPubKeys( |
196 | | (TPM_PUB_KEY)in->property, in->propertyCount, &data->pubKeys); |
197 | | break; |
198 | | case TPM_CAP_SPDM_SESSION_INFO: |
199 | | // Input property must be 0 |
200 | | if(in->property != 0) |
201 | | return TPM_RCS_VALUE + RC_GetCapability_property; |
202 | | out->moreData = SpdmCapGetSessionInfo(&data->spdmSessionInfo); |
203 | | break; |
204 | | # endif // SEC_CHANNEL_SUPPORT |
205 | 1 | case TPM_CAP_VENDOR_PROPERTY: |
206 | | // vendor property is not implemented |
207 | 1 | default: |
208 | | // Unsupported TPM_CAP value |
209 | 1 | return TPM_RCS_VALUE + RC_GetCapability_capability; |
210 | 0 | break; |
211 | 1.21k | } |
212 | 1.10k | return TPM_RC_SUCCESS; |
213 | 1.21k | } |
214 | | #endif // CC_GetCapability |
215 | | |
216 | | #include "Tpm.h" |
217 | | #include "TestParms_fp.h" |
218 | | #if CC_TestParms // Conditional expansion of this file |
219 | | TPM_RC |
220 | | TPM2_TestParms( |
221 | | TestParms_In *in // IN: input parameter list |
222 | | ) |
223 | 35 | { |
224 | | // Input parameter is not reference in command action |
225 | 35 | NOT_REFERENCED(in); |
226 | | // The parameters are tested at unmarshal process. We do nothing in command |
227 | | // action |
228 | 35 | return TPM_RC_SUCCESS; |
229 | 35 | } |
230 | | #endif // CC_TestParms |
231 | | |
232 | | #include "Tpm.h" |
233 | | #include "SetCapability_fp.h" |
234 | | |
235 | | #if CC_SetCapability // Conditional expansion of this file |
236 | | |
237 | | /*(See part 3 specification) |
238 | | // This command allows configuration of the TPM's capabilities. |
239 | | */ |
240 | | // Return Type: TPM_RC |
241 | | // TPM_RC_HANDLE value of 'property' is in an unsupported handle range |
242 | | // for the TPM_CAP_HANDLES 'capability' value |
243 | | // TPM_RC_VALUE invalid 'capability' |
244 | | TPM_RC |
245 | | TPM2_SetCapability(SetCapability_In* in // IN: input parameter list |
246 | | ) |
247 | | { |
248 | | // This reference implementation does not implement any settable capabilities. |
249 | | return TPM_RCS_VALUE + SetCapability_setCapabilityData; |
250 | | } |
251 | | |
252 | | #endif // CC_SetCapability |