Home | History | Annotate | Download | only in Tpm2CommandLib
      1 /** @file
      2   Implement TPM2 Test related command.
      3 
      4 Copyright (c) 2013, 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 <IndustryStandard/UefiTcgPlatform.h>
     16 #include <Library/Tpm2CommandLib.h>
     17 #include <Library/Tpm2DeviceLib.h>
     18 #include <Library/BaseMemoryLib.h>
     19 #include <Library/BaseLib.h>
     20 #include <Library/DebugLib.h>
     21 
     22 #pragma pack(1)
     23 
     24 typedef struct {
     25   TPM2_COMMAND_HEADER  Header;
     26   TPMI_YES_NO          FullTest;
     27 } TPM2_SELF_TEST_COMMAND;
     28 
     29 typedef struct {
     30   TPM2_RESPONSE_HEADER Header;
     31 } TPM2_SELF_TEST_RESPONSE;
     32 
     33 #pragma pack()
     34 
     35 /**
     36   This command causes the TPM to perform a test of its capabilities.
     37   If the fullTest is YES, the TPM will test all functions.
     38   If fullTest = NO, the TPM will only test those functions that have not previously been tested.
     39 
     40   @param[in] FullTest    YES if full test to be performed
     41                          NO if only test of untested functions required
     42 
     43   @retval EFI_SUCCESS      Operation completed successfully.
     44   @retval EFI_DEVICE_ERROR Unexpected device behavior.
     45 **/
     46 EFI_STATUS
     47 EFIAPI
     48 Tpm2SelfTest (
     49   IN TPMI_YES_NO          FullTest
     50   )
     51 {
     52   EFI_STATUS                        Status;
     53   TPM2_SELF_TEST_COMMAND            Cmd;
     54   TPM2_SELF_TEST_RESPONSE           Res;
     55   UINT32                            ResultBufSize;
     56 
     57   Cmd.Header.tag         = SwapBytes16(TPM_ST_NO_SESSIONS);
     58   Cmd.Header.paramSize   = SwapBytes32(sizeof(Cmd));
     59   Cmd.Header.commandCode = SwapBytes32(TPM_CC_SelfTest);
     60   Cmd.FullTest           = FullTest;
     61 
     62   ResultBufSize = sizeof(Res);
     63   Status = Tpm2SubmitCommand (sizeof(Cmd), (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);
     64 
     65   return Status;
     66 }
     67