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 "GetCapability_fp.h"
10 //
11 //
12 // Error Returns Meaning
13 //
14 // TPM_RC_HANDLE value of property is in an unsupported handle range for the
15 // TPM_CAP_HANDLES capability value
16 // TPM_RC_VALUE invalid capability; or property is not 0 for the TPM_CAP_PCRS
17 // capability value
18 //
19 TPM_RC
TPM2_GetCapability(GetCapability_In * in,GetCapability_Out * out)20 TPM2_GetCapability(
21 GetCapability_In *in, // IN: input parameter list
22 GetCapability_Out *out // OUT: output parameter list
23 )
24 {
25 // Command Output
26
27 // Set output capability type the same as input type
28 out->capabilityData.capability = in->capability;
29
30 switch(in->capability)
31 {
32 case TPM_CAP_ALGS:
33 out->moreData = AlgorithmCapGetImplemented((TPM_ALG_ID) in->property,
34 in->propertyCount, &out->capabilityData.data.algorithms);
35 break;
36 case TPM_CAP_HANDLES:
37 switch(HandleGetType((TPM_HANDLE) in->property))
38 {
39 case TPM_HT_TRANSIENT:
40 // Get list of handles of loaded transient objects
41 out->moreData = ObjectCapGetLoaded((TPM_HANDLE) in->property,
42 in->propertyCount,
43 &out->capabilityData.data.handles);
44 break;
45 case TPM_HT_PERSISTENT:
46 // Get list of handles of persistent objects
47 out->moreData = NvCapGetPersistent((TPM_HANDLE) in->property,
48 in->propertyCount,
49 &out->capabilityData.data.handles);
50 break;
51 case TPM_HT_NV_INDEX:
52 // Get list of defined NV index
53 out->moreData = NvCapGetIndex((TPM_HANDLE) in->property,
54 in->propertyCount,
55 &out->capabilityData.data.handles);
56 break;
57 case TPM_HT_LOADED_SESSION:
58 // Get list of handles of loaded sessions
59 out->moreData = SessionCapGetLoaded((TPM_HANDLE) in->property,
60 in->propertyCount,
61 &out->capabilityData.data.handles);
62 break;
63 case TPM_HT_ACTIVE_SESSION:
64 // Get list of handles of
65 out->moreData = SessionCapGetSaved((TPM_HANDLE) in->property,
66 in->propertyCount,
67 &out->capabilityData.data.handles);
68 break;
69 case TPM_HT_PCR:
70 // Get list of handles of PCR
71 out->moreData = PCRCapGetHandles((TPM_HANDLE) in->property,
72 in->propertyCount,
73 &out->capabilityData.data.handles);
74 break;
75 case TPM_HT_PERMANENT:
76 // Get list of permanent handles
77 out->moreData = PermanentCapGetHandles(
78 (TPM_HANDLE) in->property,
79 in->propertyCount,
80 &out->capabilityData.data.handles);
81 break;
82 default:
83 // Unsupported input handle type
84 return TPM_RC_HANDLE + RC_GetCapability_property;
85 break;
86 }
87 break;
88 case TPM_CAP_COMMANDS:
89 out->moreData = CommandCapGetCCList((TPM_CC) in->property,
90 in->propertyCount,
91 &out->capabilityData.data.command);
92 break;
93 case TPM_CAP_PP_COMMANDS:
94 out->moreData = PhysicalPresenceCapGetCCList((TPM_CC) in->property,
95 in->propertyCount, &out->capabilityData.data.ppCommands);
96 break;
97 case TPM_CAP_AUDIT_COMMANDS:
98 out->moreData = CommandAuditCapGetCCList((TPM_CC) in->property,
99 in->propertyCount,
100 &out->capabilityData.data.auditCommands);
101 break;
102 case TPM_CAP_PCRS:
103 // Input property must be 0
104 if(in->property != 0)
105 return TPM_RC_VALUE + RC_GetCapability_property;
106 out->moreData = PCRCapGetAllocation(in->propertyCount,
107 &out->capabilityData.data.assignedPCR);
108 break;
109 case TPM_CAP_PCR_PROPERTIES:
110 out->moreData = PCRCapGetProperties((TPM_PT_PCR) in->property,
111 in->propertyCount,
112 &out->capabilityData.data.pcrProperties);
113 break;
114 case TPM_CAP_TPM_PROPERTIES:
115 out->moreData = TPMCapGetProperties((TPM_PT) in->property,
116 in->propertyCount,
117 &out->capabilityData.data.tpmProperties);
118 break;
119 #ifdef TPM_ALG_ECC
120 case TPM_CAP_ECC_CURVES:
121 out->moreData = CryptCapGetECCCurve((TPM_ECC_CURVE ) in->property,
122 in->propertyCount,
123 &out->capabilityData.data.eccCurves);
124 break;
125 #endif // TPM_ALG_ECC
126 case TPM_CAP_VENDOR_PROPERTY:
127 // vendor property is not implemented
128 default:
129 // Unexpected TPM_CAP value
130 return TPM_RC_VALUE;
131 break;
132 }
133
134 return TPM_RC_SUCCESS;
135 }
136