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