• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 //** Includes
36 #include "Tpm.h"
37 #include "AC_spt_fp.h"
38 
39 
40 #if 1 // This is the simulated AC data.
41 
42 typedef struct {
43     TPMI_RH_AC               ac;
44     TPML_AC_CAPABILITIES    *acData;
45 
46 } acCapabilities;
47 
48 
49 TPML_AC_CAPABILITIES acData0001 = {1,
50         {{TPM_AT_PV1, 0x01234567}}};
51 
52 acCapabilities  ac[1] = { {0x0001, &acData0001} };
53 
54 #define NUM_AC  (sizeof(ac) / sizeof(acCapabilities))
55 
56 #endif // 1 The simulated AC data
57 
58 //*** AcToCapabilities()
59 // This function returns a pointer to a list of AC capabilities.
60 TPML_AC_CAPABILITIES *
AcToCapabilities(TPMI_RH_AC component)61 AcToCapabilities(
62     TPMI_RH_AC      component       // IN: component
63 )
64 {
65     UINT32          index;
66 //
67     for(index = 0; index < NUM_AC; index++)
68     {
69         if(ac[index].ac == component)
70             return ac[index].acData;
71     }
72     return NULL;
73 }
74 
75 //*** AcIsAccessible()
76 // Function to determine if an AC handle references an actual AC
77 //  Return Type: BOOL
78 BOOL
AcIsAccessible(TPM_HANDLE acHandle)79 AcIsAccessible(
80     TPM_HANDLE          acHandle
81     )
82 {
83     // In this implementation, the AC exists if there are some capabilities to go
84     // with the handle
85     return AcToCapabilities(acHandle) != NULL;
86 }
87 
88 //*** AcCapabilitiesGet()
89 // This function returns a list of capabilities associated with an AC
90 //  Return Type: TPMI_YES_NO
91 //      YES         if there are more handles available
92 //      NO          all the available handles has been returned
93 TPMI_YES_NO
AcCapabilitiesGet(TPMI_RH_AC component,TPM_AT type,TPML_AC_CAPABILITIES * capabilityList)94 AcCapabilitiesGet(
95     TPMI_RH_AC               component,     // IN: the component
96     TPM_AT                   type,          // IN: start capability type
97     TPML_AC_CAPABILITIES    *capabilityList // OUT: list of handle
98 )
99 {
100     TPMI_YES_NO              more = NO;
101     UINT32                   i;
102     TPML_AC_CAPABILITIES    *capabilities = AcToCapabilities(component);
103 
104     pAssert(HandleGetType(component) == TPM_HT_AC);
105 
106     // Initialize output handle list
107     capabilityList->count = 0;
108 
109     if(capabilities != NULL)
110     {
111         // Find the first capability less than or equal to type
112         for(i = 0; i < capabilities->count; i++)
113         {
114             if(capabilities->acCapabilities[i].tag >= type)
115             {
116                 // copy the capabilities until we run out or fill the list
117                 for(; (capabilityList->count < MAX_AC_CAPABILITIES)
118                     && (i < capabilities->count); i++)
119                 {
120                     capabilityList->acCapabilities[capabilityList->count]
121                         = capabilities->acCapabilities[i];
122                     capabilityList->count++;
123                 }
124                 more = i < capabilities->count;
125             }
126         }
127     }
128     return more;
129 }
130 
131 
132 //*** AcSendObject()
133 // Stub to handle sending of an AC object
134 //  Return Type: TPM_RC
135 TPM_RC
AcSendObject(TPM_HANDLE acHandle,OBJECT * object,TPMS_AC_OUTPUT * acDataOut)136 AcSendObject(
137     TPM_HANDLE           acHandle,      // IN: Handle of AC receiving object
138     OBJECT              *object,        // IN: object structure to send
139     TPMS_AC_OUTPUT      *acDataOut      // OUT: results of operation
140 )
141 {
142     NOT_REFERENCED(object);
143     NOT_REFERENCED(acHandle);
144     acDataOut->tag = TPM_AT_ERROR;  // indicate that the response contains an
145                                     // error code
146     acDataOut->data = TPM_AE_NONE;  // but there is no error.
147 
148     return TPM_RC_SUCCESS;
149 }
150