• 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 other
22  *  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 
36 //**Introduction
37 // This module provides the platform specific entry and fail processing. The
38 // _plat__RunCommand() function is used to call to ExecuteCommand() in the TPM code.
39 // This function does whatever processing is necessary to set up the platform
40 // in anticipation of the call to the TPM including settup for error processing.
41 //
42 // The _plat__Fail() function is called when there is a failure in the TPM. The TPM
43 // code will have set the flag to indicate that the TPM is in failure mode.
44 // This call will then recursively call ExecuteCommand in order to build the
45 // failure mode response. When ExecuteCommand() returns to _plat__Fail(), the
46 // platform will do some platform specif operation to return to the environment in
47 // which the TPM is executing. For a simulator, setjmp/longjmp is used. For an OS,
48 // a system exit to the OS would be appropriate.
49 
50 //** Includes and locals
51 #include "PlatformData.h"
52 #include "Platform_fp.h"
53 #include <setjmp.h>
54 #include "ExecCommand_fp.h"
55 #include "StmUtil.h"
56 
57 jmp_buf s_jumpBuffer;
58 
59 //** Functions
60 
61 //***_plat__RunCommand()
62 // This version of RunCommand will set up a jum_buf and call ExecuteCommand(). If
63 // the command executes without failing, it will return and RunCommand will return.
64 // If there is a failure in the command, then _plat__Fail() is called and it will
65 // longjump back to RunCommand which will call ExecuteCommand again. However, this
66 // time, the TPM will be in failure mode so ExecuteCommand will simply build
67 // a failure response and return.
68 LIB_EXPORT void
_plat__RunCommand(unsigned int requestSize,unsigned char * request,unsigned int * responseSize,unsigned char ** response)69 _plat__RunCommand(
70     unsigned int     requestSize,   // IN: command buffer size
71     unsigned char   *request,       // IN: command buffer
72     unsigned int    *responseSize,  // IN/OUT: response buffer size
73     unsigned char   **response      // IN/OUT: response buffer
74     )
75 {
76     setjmp(s_jumpBuffer);
77     ExecuteCommand((uint32_t)requestSize, request, (uint32_t*)responseSize, response);
78 }
79 
80 //***_plat__Fail()
81 // This is the platform depended failure exit for the TPM.
82 LIB_EXPORT NORETURN void
_plat__FailDetailed(char * file,int line,const char * func)83 _plat__FailDetailed(
84     char * file,
85     int line,
86     const char * func
87     )
88 {
89     dbgPrint("TPMFAIL: %s (%s@%d)\r\n", func, file, line);
90     longjmp(&s_jumpBuffer[0], 1);
91 }
92