• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   This library is TPM2 TREE protocol lib.
3 
4 Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved. <BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution.  The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9 
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 #include <Library/BaseLib.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/UefiBootServicesTableLib.h>
19 #include <Library/Tpm2DeviceLib.h>
20 #include <Protocol/TrEEProtocol.h>
21 #include <IndustryStandard/Tpm20.h>
22 
23 EFI_TREE_PROTOCOL  *mTreeProtocol = NULL;
24 
25 /**
26   This service enables the sending of commands to the TPM2.
27 
28   @param[in]      InputParameterBlockSize  Size of the TPM2 input parameter block.
29   @param[in]      InputParameterBlock      Pointer to the TPM2 input parameter block.
30   @param[in,out]  OutputParameterBlockSize Size of the TPM2 output parameter block.
31   @param[in]      OutputParameterBlock     Pointer to the TPM2 output parameter block.
32 
33   @retval EFI_SUCCESS            The command byte stream was successfully sent to the device and a response was successfully received.
34   @retval EFI_DEVICE_ERROR       The command was not successfully sent to the device or a response was not successfully received from the device.
35   @retval EFI_BUFFER_TOO_SMALL   The output parameter block is too small.
36 **/
37 EFI_STATUS
38 EFIAPI
Tpm2SubmitCommand(IN UINT32 InputParameterBlockSize,IN UINT8 * InputParameterBlock,IN OUT UINT32 * OutputParameterBlockSize,IN UINT8 * OutputParameterBlock)39 Tpm2SubmitCommand (
40   IN UINT32            InputParameterBlockSize,
41   IN UINT8             *InputParameterBlock,
42   IN OUT UINT32        *OutputParameterBlockSize,
43   IN UINT8             *OutputParameterBlock
44   )
45 {
46   EFI_STATUS                Status;
47   TPM2_RESPONSE_HEADER      *Header;
48 
49   if (mTreeProtocol == NULL) {
50     Status = gBS->LocateProtocol (&gEfiTrEEProtocolGuid, NULL, (VOID **) &mTreeProtocol);
51     if (EFI_ERROR (Status)) {
52       //
53       // TrEE protocol is not installed. So, TPM2 is not present.
54       //
55       DEBUG ((EFI_D_ERROR, "Tpm2SubmitCommand - TrEE - %r\n", Status));
56       return EFI_NOT_FOUND;
57     }
58   }
59   //
60   // Assume when TrEE Protocol is ready, RequestUseTpm already done.
61   //
62   Status = mTreeProtocol->SubmitCommand (
63                             mTreeProtocol,
64                             InputParameterBlockSize,
65                             InputParameterBlock,
66                             *OutputParameterBlockSize,
67                             OutputParameterBlock
68                             );
69   if (EFI_ERROR (Status)) {
70     return Status;
71   }
72   Header = (TPM2_RESPONSE_HEADER *)OutputParameterBlock;
73   *OutputParameterBlockSize = SwapBytes32 (Header->paramSize);
74 
75   return EFI_SUCCESS;
76 }
77 
78 /**
79   This service requests use TPM2.
80 
81   @retval EFI_SUCCESS      Get the control of TPM2 chip.
82   @retval EFI_NOT_FOUND    TPM2 not found.
83   @retval EFI_DEVICE_ERROR Unexpected device behavior.
84 **/
85 EFI_STATUS
86 EFIAPI
Tpm2RequestUseTpm(VOID)87 Tpm2RequestUseTpm (
88   VOID
89   )
90 {
91   EFI_STATUS   Status;
92 
93   if (mTreeProtocol == NULL) {
94     Status = gBS->LocateProtocol (&gEfiTrEEProtocolGuid, NULL, (VOID **) &mTreeProtocol);
95     if (EFI_ERROR (Status)) {
96       //
97       // TrEE protocol is not installed. So, TPM2 is not present.
98       //
99       DEBUG ((EFI_D_ERROR, "Tpm2RequestUseTpm - TrEE - %r\n", Status));
100       return EFI_NOT_FOUND;
101     }
102   }
103   //
104   // Assume when TrEE Protocol is ready, RequestUseTpm already done.
105   //
106   return EFI_SUCCESS;
107 }
108 
109 /**
110   This service register TPM2 device.
111 
112   @param Tpm2Device  TPM2 device
113 
114   @retval EFI_SUCCESS          This TPM2 device is registered successfully.
115   @retval EFI_UNSUPPORTED      System does not support register this TPM2 device.
116   @retval EFI_ALREADY_STARTED  System already register this TPM2 device.
117 **/
118 EFI_STATUS
119 EFIAPI
Tpm2RegisterTpm2DeviceLib(IN TPM2_DEVICE_INTERFACE * Tpm2Device)120 Tpm2RegisterTpm2DeviceLib (
121   IN TPM2_DEVICE_INTERFACE   *Tpm2Device
122   )
123 {
124   return EFI_UNSUPPORTED;
125 }
126