Coverage Report

Created: 2026-07-30 06:47

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