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 "tpm_commands.h" 18 19 #include <tss2/tss2_tpm2_types.h> 20 21 #include <cstddef> 22 #include <string> 23 TpmCommandName(std::uint32_t command_num)24std::string TpmCommandName(std::uint32_t command_num) { 25 switch(command_num) { 26 #define MATCH_TPM_COMMAND(name) case name: return #name; 27 MATCH_TPM_COMMAND(TPM2_CC_NV_UndefineSpaceSpecial) 28 MATCH_TPM_COMMAND(TPM2_CC_EvictControl) 29 MATCH_TPM_COMMAND(TPM2_CC_HierarchyControl) 30 MATCH_TPM_COMMAND(TPM2_CC_NV_UndefineSpace) 31 MATCH_TPM_COMMAND(TPM2_CC_ChangeEPS) 32 MATCH_TPM_COMMAND(TPM2_CC_ChangePPS) 33 MATCH_TPM_COMMAND(TPM2_CC_Clear) 34 MATCH_TPM_COMMAND(TPM2_CC_ClearControl) 35 MATCH_TPM_COMMAND(TPM2_CC_ClockSet) 36 MATCH_TPM_COMMAND(TPM2_CC_HierarchyChangeAuth) 37 MATCH_TPM_COMMAND(TPM2_CC_NV_DefineSpace) 38 MATCH_TPM_COMMAND(TPM2_CC_PCR_Allocate) 39 MATCH_TPM_COMMAND(TPM2_CC_PCR_SetAuthPolicy) 40 MATCH_TPM_COMMAND(TPM2_CC_PP_Commands) 41 MATCH_TPM_COMMAND(TPM2_CC_SetPrimaryPolicy) 42 MATCH_TPM_COMMAND(TPM2_CC_FieldUpgradeStart) 43 MATCH_TPM_COMMAND(TPM2_CC_ClockRateAdjust) 44 MATCH_TPM_COMMAND(TPM2_CC_CreatePrimary) 45 MATCH_TPM_COMMAND(TPM2_CC_NV_GlobalWriteLock) 46 MATCH_TPM_COMMAND(TPM2_CC_GetCommandAuditDigest) 47 MATCH_TPM_COMMAND(TPM2_CC_NV_Increment) 48 MATCH_TPM_COMMAND(TPM2_CC_NV_SetBits) 49 MATCH_TPM_COMMAND(TPM2_CC_NV_Extend) 50 MATCH_TPM_COMMAND(TPM2_CC_NV_Write) 51 MATCH_TPM_COMMAND(TPM2_CC_NV_WriteLock) 52 MATCH_TPM_COMMAND(TPM2_CC_DictionaryAttackLockReset) 53 MATCH_TPM_COMMAND(TPM2_CC_DictionaryAttackParameters) 54 MATCH_TPM_COMMAND(TPM2_CC_NV_ChangeAuth) 55 MATCH_TPM_COMMAND(TPM2_CC_PCR_Event) 56 MATCH_TPM_COMMAND(TPM2_CC_PCR_Reset) 57 MATCH_TPM_COMMAND(TPM2_CC_SequenceComplete) 58 MATCH_TPM_COMMAND(TPM2_CC_SetAlgorithmSet) 59 MATCH_TPM_COMMAND(TPM2_CC_SetCommandCodeAuditStatus) 60 MATCH_TPM_COMMAND(TPM2_CC_FieldUpgradeData) 61 MATCH_TPM_COMMAND(TPM2_CC_IncrementalSelfTest) 62 MATCH_TPM_COMMAND(TPM2_CC_SelfTest) 63 MATCH_TPM_COMMAND(TPM2_CC_Startup) 64 MATCH_TPM_COMMAND(TPM2_CC_Shutdown) 65 MATCH_TPM_COMMAND(TPM2_CC_StirRandom) 66 MATCH_TPM_COMMAND(TPM2_CC_ActivateCredential) 67 MATCH_TPM_COMMAND(TPM2_CC_Certify) 68 MATCH_TPM_COMMAND(TPM2_CC_PolicyNV) 69 MATCH_TPM_COMMAND(TPM2_CC_CertifyCreation) 70 MATCH_TPM_COMMAND(TPM2_CC_Duplicate) 71 MATCH_TPM_COMMAND(TPM2_CC_GetTime) 72 MATCH_TPM_COMMAND(TPM2_CC_GetSessionAuditDigest) 73 MATCH_TPM_COMMAND(TPM2_CC_NV_Read) 74 MATCH_TPM_COMMAND(TPM2_CC_NV_ReadLock) 75 MATCH_TPM_COMMAND(TPM2_CC_ObjectChangeAuth) 76 MATCH_TPM_COMMAND(TPM2_CC_PolicySecret) 77 MATCH_TPM_COMMAND(TPM2_CC_Rewrap) 78 MATCH_TPM_COMMAND(TPM2_CC_Create) 79 MATCH_TPM_COMMAND(TPM2_CC_ECDH_ZGen) 80 MATCH_TPM_COMMAND(TPM2_CC_HMAC) 81 MATCH_TPM_COMMAND(TPM2_CC_Import) 82 MATCH_TPM_COMMAND(TPM2_CC_Load) 83 MATCH_TPM_COMMAND(TPM2_CC_Quote) 84 MATCH_TPM_COMMAND(TPM2_CC_RSA_Decrypt) 85 MATCH_TPM_COMMAND(TPM2_CC_HMAC_Start) 86 MATCH_TPM_COMMAND(TPM2_CC_SequenceUpdate) 87 MATCH_TPM_COMMAND(TPM2_CC_Sign) 88 MATCH_TPM_COMMAND(TPM2_CC_Unseal) 89 MATCH_TPM_COMMAND(TPM2_CC_PolicySigned) 90 MATCH_TPM_COMMAND(TPM2_CC_ContextLoad) 91 MATCH_TPM_COMMAND(TPM2_CC_ContextSave) 92 MATCH_TPM_COMMAND(TPM2_CC_ECDH_KeyGen) 93 MATCH_TPM_COMMAND(TPM2_CC_EncryptDecrypt) 94 MATCH_TPM_COMMAND(TPM2_CC_FlushContext) 95 MATCH_TPM_COMMAND(TPM2_CC_LoadExternal) 96 MATCH_TPM_COMMAND(TPM2_CC_MakeCredential) 97 MATCH_TPM_COMMAND(TPM2_CC_NV_ReadPublic) 98 MATCH_TPM_COMMAND(TPM2_CC_PolicyAuthorize) 99 MATCH_TPM_COMMAND(TPM2_CC_PolicyAuthValue) 100 MATCH_TPM_COMMAND(TPM2_CC_PolicyCommandCode) 101 MATCH_TPM_COMMAND(TPM2_CC_PolicyCounterTimer) 102 MATCH_TPM_COMMAND(TPM2_CC_PolicyCpHash) 103 MATCH_TPM_COMMAND(TPM2_CC_PolicyLocality) 104 MATCH_TPM_COMMAND(TPM2_CC_PolicyNameHash) 105 MATCH_TPM_COMMAND(TPM2_CC_PolicyOR) 106 MATCH_TPM_COMMAND(TPM2_CC_PolicyTicket) 107 MATCH_TPM_COMMAND(TPM2_CC_ReadPublic) 108 MATCH_TPM_COMMAND(TPM2_CC_RSA_Encrypt) 109 MATCH_TPM_COMMAND(TPM2_CC_StartAuthSession) 110 MATCH_TPM_COMMAND(TPM2_CC_VerifySignature) 111 MATCH_TPM_COMMAND(TPM2_CC_ECC_Parameters) 112 MATCH_TPM_COMMAND(TPM2_CC_FirmwareRead) 113 MATCH_TPM_COMMAND(TPM2_CC_GetCapability) 114 MATCH_TPM_COMMAND(TPM2_CC_GetRandom) 115 MATCH_TPM_COMMAND(TPM2_CC_GetTestResult) 116 MATCH_TPM_COMMAND(TPM2_CC_Hash) 117 MATCH_TPM_COMMAND(TPM2_CC_PCR_Read) 118 MATCH_TPM_COMMAND(TPM2_CC_PolicyPCR) 119 MATCH_TPM_COMMAND(TPM2_CC_PolicyRestart) 120 MATCH_TPM_COMMAND(TPM2_CC_ReadClock) 121 MATCH_TPM_COMMAND(TPM2_CC_PCR_Extend) 122 MATCH_TPM_COMMAND(TPM2_CC_PCR_SetAuthValue) 123 MATCH_TPM_COMMAND(TPM2_CC_NV_Certify) 124 MATCH_TPM_COMMAND(TPM2_CC_EventSequenceComplete) 125 MATCH_TPM_COMMAND(TPM2_CC_HashSequenceStart) 126 MATCH_TPM_COMMAND(TPM2_CC_PolicyPhysicalPresence) 127 MATCH_TPM_COMMAND(TPM2_CC_PolicyDuplicationSelect) 128 MATCH_TPM_COMMAND(TPM2_CC_PolicyGetDigest) 129 MATCH_TPM_COMMAND(TPM2_CC_TestParms) 130 MATCH_TPM_COMMAND(TPM2_CC_Commit) 131 MATCH_TPM_COMMAND(TPM2_CC_PolicyPassword) 132 MATCH_TPM_COMMAND(TPM2_CC_ZGen_2Phase) 133 MATCH_TPM_COMMAND(TPM2_CC_EC_Ephemeral) 134 MATCH_TPM_COMMAND(TPM2_CC_PolicyNvWritten) 135 MATCH_TPM_COMMAND(TPM2_CC_PolicyTemplate) 136 MATCH_TPM_COMMAND(TPM2_CC_CreateLoaded) 137 MATCH_TPM_COMMAND(TPM2_CC_PolicyAuthorizeNV) 138 MATCH_TPM_COMMAND(TPM2_CC_EncryptDecrypt2) 139 MATCH_TPM_COMMAND(TPM2_CC_AC_GetCapability) 140 MATCH_TPM_COMMAND(TPM2_CC_AC_Send) 141 MATCH_TPM_COMMAND(TPM2_CC_Policy_AC_SendSelect) 142 MATCH_TPM_COMMAND(TPM2_CC_Vendor_TCG_Test) 143 #undef MATCH_TPM_COMMAND 144 default: 145 return "Unknown"; 146 } 147 } 148