1 /* Microsoft Reference Implementation for TPM 2.0
2 *
3 * The copyright in this software is being made available under the BSD License,
4 * included below. This software may be subject to other third party and
5 * contributor rights, including patent rights, and no such rights are granted
6 * under this license.
7 *
8 * Copyright (c) Microsoft Corporation
9 *
10 * All rights reserved.
11 *
12 * BSD License
13 *
14 * Redistribution and use in source and binary forms, with or without modification,
15 * are permitted provided that the following conditions are met:
16 *
17 * Redistributions of source code must retain the above copyright notice, this list
18 * of conditions and the following disclaimer.
19 *
20 * Redistributions in binary form must reproduce the above copyright notice, this
21 * list of conditions and the following disclaimer in the documentation and/or
22 * other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35 #include "Tpm.h"
36 #include "GetCapability_fp.h"
37
38 #if CC_GetCapability // Conditional expansion of this file
39
40 /*(See part 3 specification)
41 // This command returns various information regarding the TPM and its current
42 // state
43 */
44 // Return Type: TPM_RC
45 // TPM_RC_HANDLE value of 'property' is in an unsupported handle range
46 // for the TPM_CAP_HANDLES 'capability' value
47 // TPM_RC_VALUE invalid 'capability'; or 'property' is not 0 for the
48 // TPM_CAP_PCRS 'capability' value
49 TPM_RC
TPM2_GetCapability(GetCapability_In * in,GetCapability_Out * out)50 TPM2_GetCapability(
51 GetCapability_In *in, // IN: input parameter list
52 GetCapability_Out *out // OUT: output parameter list
53 )
54 {
55 TPMU_CAPABILITIES *data = &out->capabilityData.data;
56 // Command Output
57
58 // Set output capability type the same as input type
59 out->capabilityData.capability = in->capability;
60
61 switch(in->capability)
62 {
63 case TPM_CAP_ALGS:
64 out->moreData = AlgorithmCapGetImplemented((TPM_ALG_ID)in->property,
65 in->propertyCount,
66 &data->algorithms);
67 break;
68 case TPM_CAP_HANDLES:
69 switch(HandleGetType((TPM_HANDLE)in->property))
70 {
71 case TPM_HT_TRANSIENT:
72 // Get list of handles of loaded transient objects
73 out->moreData = ObjectCapGetLoaded((TPM_HANDLE)in->property,
74 in->propertyCount,
75 &data->handles);
76 break;
77 case TPM_HT_PERSISTENT:
78 // Get list of handles of persistent objects
79 out->moreData = NvCapGetPersistent((TPM_HANDLE)in->property,
80 in->propertyCount,
81 &data->handles);
82 break;
83 case TPM_HT_NV_INDEX:
84 // Get list of defined NV index
85 out->moreData = NvCapGetIndex((TPM_HANDLE)in->property,
86 in->propertyCount,
87 &data->handles);
88 break;
89 case TPM_HT_LOADED_SESSION:
90 // Get list of handles of loaded sessions
91 out->moreData = SessionCapGetLoaded((TPM_HANDLE)in->property,
92 in->propertyCount,
93 &data->handles);
94 break;
95 #ifdef TPM_HT_SAVED_SESSION
96 case TPM_HT_SAVED_SESSION:
97 #else
98 case TPM_HT_ACTIVE_SESSION:
99 #endif
100 // Get list of handles of
101 out->moreData = SessionCapGetSaved((TPM_HANDLE)in->property,
102 in->propertyCount,
103 &data->handles);
104 break;
105 case TPM_HT_PCR:
106 // Get list of handles of PCR
107 out->moreData = PCRCapGetHandles((TPM_HANDLE)in->property,
108 in->propertyCount,
109 &data->handles);
110 break;
111 case TPM_HT_PERMANENT:
112 // Get list of permanent handles
113 out->moreData = PermanentCapGetHandles((TPM_HANDLE)in->property,
114 in->propertyCount,
115 &data->handles);
116 break;
117 default:
118 // Unsupported input handle type
119 return TPM_RCS_HANDLE + RC_GetCapability_property;
120 break;
121 }
122 break;
123 case TPM_CAP_COMMANDS:
124 out->moreData = CommandCapGetCCList((TPM_CC)in->property,
125 in->propertyCount,
126 &data->command);
127 break;
128 case TPM_CAP_PP_COMMANDS:
129 out->moreData = PhysicalPresenceCapGetCCList((TPM_CC)in->property,
130 in->propertyCount,
131 &data->ppCommands);
132 break;
133 case TPM_CAP_AUDIT_COMMANDS:
134 out->moreData = CommandAuditCapGetCCList((TPM_CC)in->property,
135 in->propertyCount,
136 &data->auditCommands);
137 break;
138 case TPM_CAP_PCRS:
139 // Input property must be 0
140 if(in->property != 0)
141 return TPM_RCS_VALUE + RC_GetCapability_property;
142 out->moreData = PCRCapGetAllocation(in->propertyCount,
143 &data->assignedPCR);
144 break;
145 case TPM_CAP_PCR_PROPERTIES:
146 out->moreData = PCRCapGetProperties((TPM_PT_PCR)in->property,
147 in->propertyCount,
148 &data->pcrProperties);
149 break;
150 case TPM_CAP_TPM_PROPERTIES:
151 out->moreData = TPMCapGetProperties((TPM_PT)in->property,
152 in->propertyCount,
153 &data->tpmProperties);
154 break;
155 #if ALG_ECC
156 case TPM_CAP_ECC_CURVES:
157 out->moreData = CryptCapGetECCCurve((TPM_ECC_CURVE)in->property,
158 in->propertyCount,
159 &data->eccCurves);
160 break;
161 #endif // ALG_ECC
162 case TPM_CAP_AUTH_POLICIES:
163 if(HandleGetType((TPM_HANDLE)in->property) != TPM_HT_PERMANENT)
164 return TPM_RCS_VALUE + RC_GetCapability_property;
165 out->moreData = PermanentHandleGetPolicy((TPM_HANDLE)in->property,
166 in->propertyCount,
167 &data->authPolicies);
168 break;
169 case TPM_CAP_ACT:
170 if(((TPM_RH)in->property < TPM_RH_ACT_0)
171 || ((TPM_RH)in->property > TPM_RH_ACT_F))
172 return TPM_RCS_VALUE + RC_GetCapability_property;
173 out->moreData = ActGetCapabilityData((TPM_HANDLE)in->property,
174 in->propertyCount,
175 &data->actData);
176 break;
177 case TPM_CAP_VENDOR_PROPERTY:
178 // vendor property is not implemented
179 default:
180 // Unsupported TPM_CAP value
181 return TPM_RCS_VALUE + RC_GetCapability_capability;
182 break;
183 }
184
185 return TPM_RC_SUCCESS;
186 }
187
188 #endif // CC_GetCapability