1 // Copyright 2014 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef TRUNKS_ERROR_CODES_H_ 6 #define TRUNKS_ERROR_CODES_H_ 7 8 #include <string> 9 10 #include "tpm_generated.h" // For TPM_RC. 11 #include "trunks_export.h" 12 13 namespace trunks { 14 15 // Use the TPM_RC type but with different layer bits (12 - 15). Choose the layer 16 // value arbitrarily. Currently TSS2 uses 9 for TCTI and 8 for SAPI. 17 // TCTI and SAPI error codes taken from 18 // http://www.trustedcomputinggroup.org/resources/ 19 // tss_system_level_api_and_tpm_command_transmission_interface_specification 20 const TPM_RC kTrunksErrorBase = (7 << 12); 21 const TPM_RC kTctiErrorBase = (8 << 12); 22 const TPM_RC kSapiErrorBase = (9 << 12); 23 const TPM_RC kResourceManagerTpmErrorBase = (11 << 12); 24 const TPM_RC kResourceManagerErrorBase = (12 << 12); 25 26 // Note that the trunks error layer is shared with the unified error code in 27 // TPMError and related classes, see libhwsec/error/tpm_error.h for more info. 28 // From the perspective of trunks, trunks can only use kTrunksErrorBase + 0 up 29 // to kTrunksErrorBase + 1023. The other 3072 error code is reserved for use by 30 // the TPMError and related classes. 31 const TPM_RC TRUNKS_RC_AUTHORIZATION_FAILED = kTrunksErrorBase + 1; 32 const TPM_RC TRUNKS_RC_ENCRYPTION_FAILED = kTrunksErrorBase + 2; 33 const TPM_RC TRUNKS_RC_READ_ERROR = kTrunksErrorBase + 3; 34 const TPM_RC TRUNKS_RC_WRITE_ERROR = kTrunksErrorBase + 4; 35 const TPM_RC TRUNKS_RC_IPC_ERROR = kTrunksErrorBase + 5; 36 const TPM_RC TRUNKS_RC_SESSION_SETUP_ERROR = kTrunksErrorBase + 6; 37 const TPM_RC TRUNKS_RC_INVALID_TPM_CONFIGURATION = kTrunksErrorBase + 7; 38 const TPM_RC TRUNKS_RC_PARSE_ERROR = kTrunksErrorBase + 8; 39 40 const TPM_RC TCTI_RC_TRY_AGAIN = kTctiErrorBase + 1; 41 const TPM_RC TCTI_RC_GENERAL_FAILURE = kTctiErrorBase + 2; 42 const TPM_RC TCTI_RC_BAD_CONTEXT = kTctiErrorBase + 3; 43 const TPM_RC TCTI_RC_WRONG_ABI_VERSION = kTctiErrorBase + 4; 44 const TPM_RC TCTI_RC_NOT_IMPLEMENTED = kTctiErrorBase + 5; 45 const TPM_RC TCTI_RC_BAD_PARAMETER = kTctiErrorBase + 6; 46 const TPM_RC TCTI_RC_INSUFFICIENT_BUFFER = kTctiErrorBase + 7; 47 const TPM_RC TCTI_RC_NO_CONNECTION = kTctiErrorBase + 8; 48 const TPM_RC TCTI_RC_DRIVER_NOT_FOUND = kTctiErrorBase + 9; 49 const TPM_RC TCTI_RC_DRIVERINFO_NOT_FOUND = kTctiErrorBase + 10; 50 const TPM_RC TCTI_RC_NO_RESPONSE = kTctiErrorBase + 11; 51 const TPM_RC TCTI_RC_BAD_VALUE = kTctiErrorBase + 12; 52 53 const TPM_RC SAPI_RC_INVALID_SESSIONS = kSapiErrorBase + 1; 54 const TPM_RC SAPI_RC_ABI_MISMATCH = kSapiErrorBase + 2; 55 const TPM_RC SAPI_RC_INSUFFICIENT_BUFFER = kSapiErrorBase + 3; 56 const TPM_RC SAPI_RC_BAD_PARAMETER = kSapiErrorBase + 4; 57 const TPM_RC SAPI_RC_BAD_SEQUENCE = kSapiErrorBase + 5; 58 const TPM_RC SAPI_RC_NO_DECRYPT_PARAM = kSapiErrorBase + 6; 59 const TPM_RC SAPI_RC_NO_ENCRYPT_PARAM = kSapiErrorBase + 7; 60 const TPM_RC SAPI_RC_NO_RESPONSE_RECEIVED = kSapiErrorBase + 8; 61 const TPM_RC SAPI_RC_BAD_SIZE = kSapiErrorBase + 9; 62 const TPM_RC SAPI_RC_CORRUPTED_DATA = kSapiErrorBase + 10; 63 const TPM_RC SAPI_RC_INSUFFICIENT_CONTEXT = kSapiErrorBase + 11; 64 const TPM_RC SAPI_RC_INSUFFICIENT_RESPONSE = kSapiErrorBase + 12; 65 const TPM_RC SAPI_RC_INCOMPATIBLE_TCTI = kSapiErrorBase + 13; 66 const TPM_RC SAPI_RC_MALFORMED_RESPONSE = kSapiErrorBase + 14; 67 const TPM_RC SAPI_RC_BAD_TCTI_STRUCTURE = kSapiErrorBase + 15; 68 const TPM_RC SAPI_RC_NO_CONNECTION = kSapiErrorBase + 16; 69 70 // Returns a description of |error|. 71 TRUNKS_EXPORT std::string GetErrorString(TPM_RC error); 72 73 // Strips the P and N bits from a 'format one' error. If the given error code 74 // is not a format one error, it is returned as is. The error that is returned 75 // can be compared to TPM_RC_* constant values. See TPM 2.0 Part 2 Section 6.6 76 // for details on format one errors. 77 TRUNKS_EXPORT TPM_RC GetFormatOneError(TPM_RC error); 78 79 // Creates a well-formed response with the given |error_code|. 80 TRUNKS_EXPORT std::string CreateErrorResponse(TPM_RC error_code); 81 82 // Retrieves response code, |rc|, from the response string, |response|. 83 // Return TPM_RC_SUCCESS iff success. 84 TRUNKS_EXPORT TPM_RC GetResponseCode(const std::string& response, TPM_RC& rc); 85 86 } // namespace trunks 87 88 #endif // TRUNKS_ERROR_CODES_H_ 89