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 /*(Auto-generated) 36 * Created by TpmPrototypes; Version 3.0 July 18, 2017 37 * Date: Mar 4, 2020 Time: 02:36:45PM 38 */ 39 40 #ifndef _SIMULATOR_FP_H_ 41 #define _SIMULATOR_FP_H_ 42 43 //** From TcpServer.c 44 45 #ifdef _MSC_VER 46 #elif defined(__unix__) 47 #endif 48 49 //*** PlatformServer() 50 // This function processes incoming platform requests. 51 bool 52 PlatformServer( 53 SOCKET s 54 ); 55 56 //*** PlatformSvcRoutine() 57 // This function is called to set up the socket interfaces to listen for 58 // commands. 59 DWORD WINAPI 60 PlatformSvcRoutine( 61 LPVOID port 62 ); 63 64 //*** PlatformSignalService() 65 // This function starts a new thread waiting for platform signals. 66 // Platform signals are processed one at a time in the order in which they are 67 // received. 68 int 69 PlatformSignalService( 70 int PortNumber 71 ); 72 73 //*** RegularCommandService() 74 // This function services regular commands. 75 int 76 RegularCommandService( 77 int PortNumber 78 ); 79 80 //*** StartTcpServer() 81 // This is the main entry-point to the TCP server. The server listens on port 82 // specified. 83 // 84 // Note that there is no way to specify the network interface in this implementation. 85 int 86 StartTcpServer( 87 int PortNumber 88 ); 89 90 //*** ReadBytes() 91 // This function reads the indicated number of bytes ('NumBytes') into buffer 92 // from the indicated socket. 93 bool 94 ReadBytes( 95 SOCKET s, 96 char *buffer, 97 int NumBytes 98 ); 99 100 //*** WriteBytes() 101 // This function will send the indicated number of bytes ('NumBytes') to the 102 // indicated socket 103 bool 104 WriteBytes( 105 SOCKET s, 106 char *buffer, 107 int NumBytes 108 ); 109 110 //*** WriteUINT32() 111 // Send 4 byte integer 112 bool 113 WriteUINT32( 114 SOCKET s, 115 uint32_t val 116 ); 117 118 //*** ReadUINT32() 119 // Function to read 4 byte integer from socket. 120 bool 121 ReadUINT32( 122 SOCKET s, 123 uint32_t *val 124 ); 125 126 //*** ReadVarBytes() 127 // Get a uint32-length-prepended binary array. Note that the 4-byte length is 128 // in network byte order (big-endian). 129 bool 130 ReadVarBytes( 131 SOCKET s, 132 char *buffer, 133 uint32_t *BytesReceived, 134 int MaxLen 135 ); 136 137 //*** WriteVarBytes() 138 // Send a UINT32-length-prepended binary array. Note that the 4-byte length is 139 // in network byte order (big-endian). 140 bool 141 WriteVarBytes( 142 SOCKET s, 143 char *buffer, 144 int BytesToSend 145 ); 146 147 //*** TpmServer() 148 // Processing incoming TPM command requests using the protocol / interface 149 // defined above. 150 bool 151 TpmServer( 152 SOCKET s 153 ); 154 155 156 //** From TPMCmdp.c 157 158 #ifdef _MSC_VER 159 #elif defined(__unix__) 160 #endif 161 162 //*** Signal_PowerOn() 163 // This function processes a power-on indication. Among other things, it 164 // calls the _TPM_Init() handler. 165 void 166 _rpc__Signal_PowerOn( 167 bool isReset 168 ); 169 170 //*** Signal_Restart() 171 // This function processes the clock restart indication. All it does is call 172 // the platform function. 173 void 174 _rpc__Signal_Restart( 175 void 176 ); 177 178 //***Signal_PowerOff() 179 // This function processes the power off indication. Its primary function is 180 // to set a flag indicating that the next power on indication should cause 181 // _TPM_Init() to be called. 182 void 183 _rpc__Signal_PowerOff( 184 void 185 ); 186 187 //*** _rpc__ForceFailureMode() 188 // This function is used to debug the Failure Mode logic of the TPM. It will set 189 // a flag in the TPM code such that the next call to TPM2_SelfTest() will result 190 // in a failure, putting the TPM into Failure Mode. 191 void 192 _rpc__ForceFailureMode( 193 void 194 ); 195 196 //*** _rpc__Signal_PhysicalPresenceOn() 197 // This function is called to simulate activation of the physical presence "pin". 198 void 199 _rpc__Signal_PhysicalPresenceOn( 200 void 201 ); 202 203 //*** _rpc__Signal_PhysicalPresenceOff() 204 // This function is called to simulate deactivation of the physical presence "pin". 205 void 206 _rpc__Signal_PhysicalPresenceOff( 207 void 208 ); 209 210 //*** _rpc__Signal_Hash_Start() 211 // This function is called to simulate a _TPM_Hash_Start event. It will call 212 // 213 void 214 _rpc__Signal_Hash_Start( 215 void 216 ); 217 218 //*** _rpc__Signal_Hash_Data() 219 // This function is called to simulate a _TPM_Hash_Data event. 220 void 221 _rpc__Signal_Hash_Data( 222 _IN_BUFFER input 223 ); 224 225 //*** _rpc__Signal_HashEnd() 226 // This function is called to simulate a _TPM_Hash_End event. 227 void 228 _rpc__Signal_HashEnd( 229 void 230 ); 231 232 //*** _rpc__Send_Command() 233 // This is the interface to the TPM code. 234 // Return Type: void 235 void 236 _rpc__Send_Command( 237 unsigned char locality, 238 _IN_BUFFER request, 239 _OUT_BUFFER *response 240 ); 241 242 //*** _rpc__Signal_CancelOn() 243 // This function is used to turn on the indication to cancel a command in process. 244 // An executing command is not interrupted. The command code may periodically check 245 // this indication to see if it should abort the current command processing and 246 // returned TPM_RC_CANCELLED. 247 void 248 _rpc__Signal_CancelOn( 249 void 250 ); 251 252 //*** _rpc__Signal_CancelOff() 253 // This function is used to turn off the indication to cancel a command in process. 254 void 255 _rpc__Signal_CancelOff( 256 void 257 ); 258 259 //*** _rpc__Signal_NvOn() 260 // In a system where the NV memory used by the TPM is not within the TPM, the 261 // NV may not always be available. This function turns on the indicator that 262 // indicates that NV is available. 263 void 264 _rpc__Signal_NvOn( 265 void 266 ); 267 268 //*** _rpc__Signal_NvOff() 269 // This function is used to set the indication that NV memory is no 270 // longer available. 271 void 272 _rpc__Signal_NvOff( 273 void 274 ); 275 276 //*** _rpc__RsaKeyCacheControl() 277 // This function is used to enable/disable the use of the RSA key cache during 278 // simulation. 279 void 280 _rpc__RsaKeyCacheControl( 281 int state 282 ); 283 284 //*** _rpc__ACT_GetSignaled() 285 // This function is used to count the ACT second tick. 286 bool 287 _rpc__ACT_GetSignaled( 288 uint32_t actHandle 289 ); 290 291 292 //** From TPMCmds.c 293 294 //*** main() 295 // This is the main entry point for the simulator. 296 // It registers the interface and starts listening for clients 297 int 298 main( 299 int argc, 300 char *argv[] 301 ); 302 303 #endif // _SIMULATOR_FP_H_ 304