1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "commands.h" 18 19 #include <linux/vtpm_proxy.h> 20 #include <tss2/tss2_tpm2_types.h> 21 22 #include <cstddef> 23 #include <string> 24 TpmCommandName(std::uint32_t command_num)25std::string TpmCommandName(std::uint32_t command_num) { 26 switch(command_num) { 27 #define MATCH_TPM_COMMAND(name) case name: return #name; 28 MATCH_TPM_COMMAND(TPM2_CC_NV_UndefineSpaceSpecial) 29 MATCH_TPM_COMMAND(TPM2_CC_EvictControl) 30 MATCH_TPM_COMMAND(TPM2_CC_HierarchyControl) 31 MATCH_TPM_COMMAND(TPM2_CC_NV_UndefineSpace) 32 MATCH_TPM_COMMAND(TPM2_CC_ChangeEPS) 33 MATCH_TPM_COMMAND(TPM2_CC_ChangePPS) 34 MATCH_TPM_COMMAND(TPM2_CC_Clear) 35 MATCH_TPM_COMMAND(TPM2_CC_ClearControl) 36 MATCH_TPM_COMMAND(TPM2_CC_ClockSet) 37 MATCH_TPM_COMMAND(TPM2_CC_HierarchyChangeAuth) 38 MATCH_TPM_COMMAND(TPM2_CC_NV_DefineSpace) 39 MATCH_TPM_COMMAND(TPM2_CC_PCR_Allocate) 40 MATCH_TPM_COMMAND(TPM2_CC_PCR_SetAuthPolicy) 41 MATCH_TPM_COMMAND(TPM2_CC_PP_Commands) 42 MATCH_TPM_COMMAND(TPM2_CC_SetPrimaryPolicy) 43 MATCH_TPM_COMMAND(TPM2_CC_FieldUpgradeStart) 44 MATCH_TPM_COMMAND(TPM2_CC_ClockRateAdjust) 45 MATCH_TPM_COMMAND(TPM2_CC_CreatePrimary) 46 MATCH_TPM_COMMAND(TPM2_CC_NV_GlobalWriteLock) 47 MATCH_TPM_COMMAND(TPM2_CC_GetCommandAuditDigest) 48 MATCH_TPM_COMMAND(TPM2_CC_NV_Increment) 49 MATCH_TPM_COMMAND(TPM2_CC_NV_SetBits) 50 MATCH_TPM_COMMAND(TPM2_CC_NV_Extend) 51 MATCH_TPM_COMMAND(TPM2_CC_NV_Write) 52 MATCH_TPM_COMMAND(TPM2_CC_NV_WriteLock) 53 MATCH_TPM_COMMAND(TPM2_CC_DictionaryAttackLockReset) 54 MATCH_TPM_COMMAND(TPM2_CC_DictionaryAttackParameters) 55 MATCH_TPM_COMMAND(TPM2_CC_NV_ChangeAuth) 56 MATCH_TPM_COMMAND(TPM2_CC_PCR_Event) 57 MATCH_TPM_COMMAND(TPM2_CC_PCR_Reset) 58 MATCH_TPM_COMMAND(TPM2_CC_SequenceComplete) 59 MATCH_TPM_COMMAND(TPM2_CC_SetAlgorithmSet) 60 MATCH_TPM_COMMAND(TPM2_CC_SetCommandCodeAuditStatus) 61 MATCH_TPM_COMMAND(TPM2_CC_FieldUpgradeData) 62 MATCH_TPM_COMMAND(TPM2_CC_IncrementalSelfTest) 63 MATCH_TPM_COMMAND(TPM2_CC_SelfTest) 64 MATCH_TPM_COMMAND(TPM2_CC_Startup) 65 MATCH_TPM_COMMAND(TPM2_CC_Shutdown) 66 MATCH_TPM_COMMAND(TPM2_CC_StirRandom) 67 MATCH_TPM_COMMAND(TPM2_CC_ActivateCredential) 68 MATCH_TPM_COMMAND(TPM2_CC_Certify) 69 MATCH_TPM_COMMAND(TPM2_CC_PolicyNV) 70 MATCH_TPM_COMMAND(TPM2_CC_CertifyCreation) 71 MATCH_TPM_COMMAND(TPM2_CC_Duplicate) 72 MATCH_TPM_COMMAND(TPM2_CC_GetTime) 73 MATCH_TPM_COMMAND(TPM2_CC_GetSessionAuditDigest) 74 MATCH_TPM_COMMAND(TPM2_CC_NV_Read) 75 MATCH_TPM_COMMAND(TPM2_CC_NV_ReadLock) 76 MATCH_TPM_COMMAND(TPM2_CC_ObjectChangeAuth) 77 MATCH_TPM_COMMAND(TPM2_CC_PolicySecret) 78 MATCH_TPM_COMMAND(TPM2_CC_Rewrap) 79 MATCH_TPM_COMMAND(TPM2_CC_Create) 80 MATCH_TPM_COMMAND(TPM2_CC_ECDH_ZGen) 81 MATCH_TPM_COMMAND(TPM2_CC_HMAC) 82 MATCH_TPM_COMMAND(TPM2_CC_Import) 83 MATCH_TPM_COMMAND(TPM2_CC_Load) 84 MATCH_TPM_COMMAND(TPM2_CC_Quote) 85 MATCH_TPM_COMMAND(TPM2_CC_RSA_Decrypt) 86 MATCH_TPM_COMMAND(TPM2_CC_HMAC_Start) 87 MATCH_TPM_COMMAND(TPM2_CC_SequenceUpdate) 88 MATCH_TPM_COMMAND(TPM2_CC_Sign) 89 MATCH_TPM_COMMAND(TPM2_CC_Unseal) 90 MATCH_TPM_COMMAND(TPM2_CC_PolicySigned) 91 MATCH_TPM_COMMAND(TPM2_CC_ContextLoad) 92 MATCH_TPM_COMMAND(TPM2_CC_ContextSave) 93 MATCH_TPM_COMMAND(TPM2_CC_ECDH_KeyGen) 94 MATCH_TPM_COMMAND(TPM2_CC_EncryptDecrypt) 95 MATCH_TPM_COMMAND(TPM2_CC_FlushContext) 96 MATCH_TPM_COMMAND(TPM2_CC_LoadExternal) 97 MATCH_TPM_COMMAND(TPM2_CC_MakeCredential) 98 MATCH_TPM_COMMAND(TPM2_CC_NV_ReadPublic) 99 MATCH_TPM_COMMAND(TPM2_CC_PolicyAuthorize) 100 MATCH_TPM_COMMAND(TPM2_CC_PolicyAuthValue) 101 MATCH_TPM_COMMAND(TPM2_CC_PolicyCommandCode) 102 MATCH_TPM_COMMAND(TPM2_CC_PolicyCounterTimer) 103 MATCH_TPM_COMMAND(TPM2_CC_PolicyCpHash) 104 MATCH_TPM_COMMAND(TPM2_CC_PolicyLocality) 105 MATCH_TPM_COMMAND(TPM2_CC_PolicyNameHash) 106 MATCH_TPM_COMMAND(TPM2_CC_PolicyOR) 107 MATCH_TPM_COMMAND(TPM2_CC_PolicyTicket) 108 MATCH_TPM_COMMAND(TPM2_CC_ReadPublic) 109 MATCH_TPM_COMMAND(TPM2_CC_RSA_Encrypt) 110 MATCH_TPM_COMMAND(TPM2_CC_StartAuthSession) 111 MATCH_TPM_COMMAND(TPM2_CC_VerifySignature) 112 MATCH_TPM_COMMAND(TPM2_CC_ECC_Parameters) 113 MATCH_TPM_COMMAND(TPM2_CC_FirmwareRead) 114 MATCH_TPM_COMMAND(TPM2_CC_GetCapability) 115 MATCH_TPM_COMMAND(TPM2_CC_GetRandom) 116 MATCH_TPM_COMMAND(TPM2_CC_GetTestResult) 117 MATCH_TPM_COMMAND(TPM2_CC_Hash) 118 MATCH_TPM_COMMAND(TPM2_CC_PCR_Read) 119 MATCH_TPM_COMMAND(TPM2_CC_PolicyPCR) 120 MATCH_TPM_COMMAND(TPM2_CC_PolicyRestart) 121 MATCH_TPM_COMMAND(TPM2_CC_ReadClock) 122 MATCH_TPM_COMMAND(TPM2_CC_PCR_Extend) 123 MATCH_TPM_COMMAND(TPM2_CC_PCR_SetAuthValue) 124 MATCH_TPM_COMMAND(TPM2_CC_NV_Certify) 125 MATCH_TPM_COMMAND(TPM2_CC_EventSequenceComplete) 126 MATCH_TPM_COMMAND(TPM2_CC_HashSequenceStart) 127 MATCH_TPM_COMMAND(TPM2_CC_PolicyPhysicalPresence) 128 MATCH_TPM_COMMAND(TPM2_CC_PolicyDuplicationSelect) 129 MATCH_TPM_COMMAND(TPM2_CC_PolicyGetDigest) 130 MATCH_TPM_COMMAND(TPM2_CC_TestParms) 131 MATCH_TPM_COMMAND(TPM2_CC_Commit) 132 MATCH_TPM_COMMAND(TPM2_CC_PolicyPassword) 133 MATCH_TPM_COMMAND(TPM2_CC_ZGen_2Phase) 134 MATCH_TPM_COMMAND(TPM2_CC_EC_Ephemeral) 135 MATCH_TPM_COMMAND(TPM2_CC_PolicyNvWritten) 136 MATCH_TPM_COMMAND(TPM2_CC_PolicyTemplate) 137 MATCH_TPM_COMMAND(TPM2_CC_CreateLoaded) 138 MATCH_TPM_COMMAND(TPM2_CC_PolicyAuthorizeNV) 139 MATCH_TPM_COMMAND(TPM2_CC_EncryptDecrypt2) 140 MATCH_TPM_COMMAND(TPM2_CC_AC_GetCapability) 141 MATCH_TPM_COMMAND(TPM2_CC_AC_Send) 142 MATCH_TPM_COMMAND(TPM2_CC_Policy_AC_SendSelect) 143 MATCH_TPM_COMMAND(TPM2_CC_Vendor_TCG_Test) 144 MATCH_TPM_COMMAND(TPM2_CC_SET_LOCALITY) 145 #undef MATCH_TPM_COMMAND 146 default: 147 return "Unknown"; 148 } 149 } 150