| 1 |
/* Microsoft Reference Implementation for TPM 2.0 |
| 2 |
* |
| 3 |
* The copyright in this software is being made available under the BSD |
| 4 |
* License, included below. This software may be subject to other third party |
| 5 |
* and contributor rights, including patent rights, and no such rights are |
| 6 |
* granted 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 |
| 15 |
* modification, are permitted provided that the following conditions are met: |
| 16 |
* |
| 17 |
* Redistributions of source code must retain the above copyright notice, this |
| 18 |
* list of conditions and the following disclaimer. |
| 19 |
* |
| 20 |
* Redistributions in binary form must reproduce the above copyright notice, |
| 21 |
* this list of conditions and the following disclaimer in the documentation |
| 22 |
* and/or other materials provided with the distribution. |
| 23 |
* |
| 24 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS |
| 25 |
* IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 26 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 27 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 28 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 29 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 30 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 31 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 32 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 33 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 34 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 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 |
| 39 |
// code. This function does whatever processing is necessary to set up the |
| 40 |
// platform in anticipation of the call to the TPM including settup for error |
| 41 |
// processing. |
| 42 |
// |
| 43 |
// The _plat__Fail() function is called when there is a failure in the TPM. The |
| 44 |
// TPM code will have set the flag to indicate that the TPM is in failure mode. |
| 45 |
// This call will then recursively call ExecuteCommand in order to build the |
| 46 |
// failure mode response. When ExecuteCommand() returns to _plat__Fail(), the |
| 47 |
// platform will do some platform specif operation to return to the environment |
| 48 |
// in which the TPM is executing. For a simulator, setjmp/longjmp is used. For |
| 49 |
// an OS, a system exit to the OS would be appropriate. |
| 50 |
|
| 51 |
#include <setjmp.h> |
| 52 |
|
| 53 |
#include "CompilerDependencies.h" |
| 54 |
#include "ExecCommand_fp.h" |
| 55 |
#include "Manufacture_fp.h" |
| 56 |
#include "Platform.h" |
| 57 |
#include "Platform_fp.h" |
| 58 |
#include "_TPM_Init_fp.h" |
| 59 |
|
| 60 |
jmp_buf s_jumpBuffer; |
| 61 |
|
| 62 |
void _plat__RunCommand(uint32_t requestSize, unsigned char *request, |
| 63 |
uint32_t *responseSize, unsigned char **response) { |
| 64 |
setjmp(s_jumpBuffer); |
| 65 |
ExecuteCommand(requestSize, request, responseSize, response); |
| 66 |
} |
| 67 |
|
| 68 |
_Noreturn void _plat__Fail(void) { longjmp(&s_jumpBuffer[0], 1); } |
| 69 |
|
| 70 |
void _plat__Reset(bool forceManufacture) { |
| 71 |
// We ignore errors, as we don't care if the TPM has been Manufactured before. |
| 72 |
if (forceManufacture) { |
| 73 |
TPM_TearDown(); |
| 74 |
} |
| 75 |
TPM_Manufacture(0); |
| 76 |
_plat__TimerReset(); |
| 77 |
_TPM_Init(); |
| 78 |
} |