#ifndef _ERROR_CODES_H_
#define _ERROR_CODES_H_
/*******************************************
 *
 * Error codes.
 *
 ********************************************/

#define ERR_BASE                           (int32_t)  -10000
#define NOT_ERROR                          0
#define ERR_UNSUPPORTED_CMD                ERR_BASE + (int32_t) -1
#define ERR_INVALID_ARGUMENT               ERR_BASE + (int32_t) -2
#define ERR_BUFFER_OVERFLOW                ERR_BASE + (int32_t) -3
#define ERR_NOT_ENOUGH_MEMORY              ERR_BASE + (int32_t) -4
#define ERR_PERMISSION_DENIED              ERR_BASE + (int32_t) -5
#define ERR_NOT_IMPLEMENTED                ERR_BASE + (int32_t) -6
#define ERR_FILE_READ_FAILED               ERR_BASE + (int32_t) -7
#define ERR_FILE_WRITE_FAILED              ERR_BASE + (int32_t) -8
#define ERR_INVALID_BLOB                   ERR_BASE + (int32_t) -9
#define ERR_DRK_IS_NOT_EXIST               ERR_BASE + (int32_t) -10
#define ERR_WRONG_ORDER                    ERR_BASE + (int32_t) -11
#define ERR_BASE64_CODING_FAILED           ERR_BASE + (int32_t) -12
#define ERR_HASH_VERIFICATION_FAILED       ERR_BASE + (int32_t) -13
#define ERR_UNSUPPORTED_DRKV2_UID_FORMAT   ERR_BASE + (int32_t) -14
#define ERR_RAND_BYTE_FAILED               ERR_BASE + (int32_t) -15
#define ERR_D2I_PUBKEY_FAILED              ERR_BASE + (int32_t) -16
#define ERR_WRONG_SIZE                     ERR_BASE + (int32_t) -17
#define ERR_FILE_DRK_READ_FAILED           ERR_BASE + (int32_t) -18
#define ERR_UNSUPPORTED_DEVINFO            ERR_BASE + (int32_t) -19
#define ERR_GET_BIGDATA_MSG                ERR_BASE + (int32_t) -20
#define ERR_DRK_SESSION_BUSY               ERR_BASE + (int32_t) -21
#define ERR_NOT_CREATE_HANDLER             ERR_BASE + (int32_t) -22

/* lock */
#define ERR_TIMEOUT_TO_LOCK                ERR_BASE + (int32_t) -30
#define ERR_LOCK_TO_HOLD                   ERR_BASE + (int32_t) -31

/* match */
#define ERR_NOT_MATCHED                    ERR_BASE + (int32_t) -50
#define ERR_MATCH_GET_WRONG_TLV            ERR_BASE + (int32_t) -51
#define ERR_MATCH_GET_MODELNAME            ERR_BASE + (int32_t) -52

#define ERR_BAD_REQUEST_LEN                ERR_BASE + (int32_t) -53
#define ERR_BYTES_ASSIGN                   ERR_BASE + (int32_t) -54

#define ERR_TLV_NOT_FOUND                  ERR_BASE + (int32_t) -55
#define ERR_TLV_ENCODE_FAILED              ERR_BASE + (int32_t) -56
#define ERR_TLV_DECODE_FAILED              ERR_BASE + (int32_t) -57

#define ERR_GET_FILE_SIZE                  ERR_BASE + (int32_t) -80

#define ERR_WB_API_OPERATION_FAILED        ERR_BASE + (int32_t) -100
#define ERR_SYSCALL_FAILED                 ERR_BASE + (int32_t) -101
#define ERR_PLATFORM_API_OPERATION_FAILED  ERR_BASE + (int32_t) -102
#define ERR_DRIVER_API_OPERATION_FAILED    ERR_BASE + (int32_t) -103
#define ERR_TA_LOADING_FAILED              ERR_BASE + (int32_t) -104
#define ERR_OPENSSL_API_FAILED             ERR_BASE + (int32_t) -105
#define ERR_TA_UNLOADING_FAILED            ERR_BASE + (int32_t) -106

//Vendor error
#define ERR_VND_BASE                       ERR_BASE + (int32_t) -200
#define ERR_VND_NOT_ALLOWD_UID             ERR_VND_BASE + (int32_t) -1
#define ERR_VND_DEAD_OBJECT                ERR_VND_BASE + (int32_t) -2

#define ERR_EVP_BASE                       ERR_BASE + (int32_t) -500
#define ERR_EVP_CIPHER_NEW_FAILED          ERR_EVP_BASE + (int32_t) -1
#define ERR_EVP_CIPHER_INIT_FAILED         ERR_EVP_BASE + (int32_t) -2
#define ERR_EVP_CIPHER_UPDATE_FAILED       ERR_EVP_BASE + (int32_t) -3
#define ERR_EVP_CIPHER_FINAL_FAILED        ERR_EVP_BASE + (int32_t) -4
#define ERR_EVP_PKEY_ENC_INIT_FAILED       ERR_EVP_BASE + (int32_t) -5
#define ERR_EVP_SET_RSA_PADDING_FAILED     ERR_EVP_BASE + (int32_t) -6
#define ERR_EVP_PKEY_ENC_FAILED            ERR_EVP_BASE + (int32_t) -7

#define ERR_RILD_BASE                      ERR_BASE + (int32_t) -1000
#define ERR_WAIT_CONDITION_ERROR           ERR_RILD_BASE + ( int32_t ) -1
#define ERR_RILD_CONNECT_ERROR             ERR_RILD_BASE + ( int32_t ) -2
#define ERR_RILD_REQUEST_HOOK_ERROR        ERR_RILD_BASE + ( int32_t ) -3
#define ERR_RILD_SET_HANDLER_ERROR         ERR_RILD_BASE + ( int32_t ) -83

//DBUS error
#define ERR_GBUS_BASE                      ERR_BASE      + (int32_t) -1100
#define ERR_GBUS_GET_VARIANT_FAILED        ERR_GBUS_BASE + (int32_t) -1
#define ERR_GBUS_SEND_SIGNAL_FAILED        ERR_GBUS_BASE + (int32_t) -2
#define ERR_GBUS_RECV_SIGNAL_INVALID       ERR_GBUS_BASE + (int32_t) -3
#define ERR_GBUS_INIT_FAILED               ERR_GBUS_BASE + (int32_t) -4

#define ERR_KEYMASTER_BASE                 ERR_BASE + (int32_t) -1500
#define ERR_KEYMASTER_UNKNOWN_ERROR        ERR_KEYMASTER_BASE + ( int32_t ) -1
#define ERR_KEYMASTER_PACKING_ERROR        ERR_KEYMASTER_BASE + ( int32_t ) -2
#define ERR_KEYMASTER_UNPACKING_ERROR      ERR_KEYMASTER_BASE + ( int32_t ) -3
#define ERR_KEYMASTER_NULL_POINTER         ERR_KEYMASTER_BASE + ( int32_t ) -4
#define ERR_KEYMASTER_INVALID_OUT_SIZE     ERR_KEYMASTER_BASE + ( int32_t ) -5
#define ERR_KEYMASTER_INVALID_KEY_BLOB     ERR_KEYMASTER_BASE + ( int32_t ) -6
#define ERR_KEYMASTER_TZ_COMMUNICATE_ERROR ERR_KEYMASTER_BASE + ( int32_t ) -7

#define ERR_TA_BASE                        ERR_BASE + (int32_t) -2000
#define ERR_TA_UNSUPPORTED_CMD             ERR_TA_BASE + (int32_t) -1
#define ERR_TA_INVALID_ARGUMENT            ERR_TA_BASE + (int32_t) -2
#define ERR_TA_BUFFER_OVERFLOW             ERR_TA_BASE + (int32_t) -3
#define ERR_TA_NOT_ENOUGH_MEMORY           ERR_TA_BASE + (int32_t) -4
#define ERR_TA_PARSING_FAILED              ERR_TA_BASE + (int32_t) -5
#define ERR_TA_KEYPAIR_MISMATCHED          ERR_TA_BASE + (int32_t) -6
#define ERR_TA_VERIFICATION_FAILED         ERR_TA_BASE + (int32_t) -7
#define ERR_TA_INVALID_BLOB                ERR_TA_BASE + (int32_t) -8
#define ERR_TA_NOT_SECURE                  ERR_TA_BASE + (int32_t) -9
#define ERR_TA_REVOCATED_CERT              ERR_TA_BASE + (int32_t) -10
#define ERR_TA_GEN_RANDOM_FAILED           ERR_TA_BASE + (int32_t) -11
#define ERR_TA_GEN_HASH_FAILED             ERR_TA_BASE + (int32_t) -12
#define ERR_TA_CRYPTO_API_ERROR            ERR_TA_BASE + (int32_t) -13
#define ERR_TA_PERMISSION_DENIED           ERR_TA_BASE + (int32_t) -14
#define ERR_TA_INVALID_KEY_LENGTH          ERR_TA_BASE + (int32_t) -15
#define ERR_TA_INVALID_TLV_ATTR            ERR_TA_BASE + (int32_t) -16
#define ERR_TA_GEN_ASN1_FAILED             ERR_TA_BASE + (int32_t) -17
#define ERR_SECURE_BOOT_DISABLED           ERR_TA_BASE + (int32_t) -18
#define ERR_FROM_HWVAULT                   ERR_TA_BASE + (int32_t) -19
// 101 ~ 409 are reserved by TlApiError.h

#define ERR_TA_SWB_BASE                    ERR_BASE + (int32_t) -3000
#define ERR_TA_SWB_FAILURE                 ERR_TA_SWB_BASE + (int32_t) -1
#define ERR_TA_SWB_PARAM_CTX_NULL          ERR_TA_SWB_BASE + (int32_t) -2
#define ERR_TA_SWB_PARAM_KEY_NULL          ERR_TA_SWB_BASE + (int32_t) -3
#define ERR_TA_SWB_PARAM_IV_NULL           ERR_TA_SWB_BASE + (int32_t) -4
#define ERR_TA_SWB_PARAM_OUT_NULL          ERR_TA_SWB_BASE + (int32_t) -5
#define ERR_TA_SWB_PARAM_IN_NULL           ERR_TA_SWB_BASE + (int32_t) -6
#define ERR_TA_SWB_PARAM_IN_LENGTH_INVALID ERR_TA_SWB_BASE + (int32_t) -7
#define ERR_TA_SWB_PARAM_OUT_LENGTH_NULL   ERR_TA_SWB_BASE + (int32_t) -8
#define ERR_TA_SWB_FILE_OPEN_FAILED        ERR_TA_SWB_BASE + (int32_t) -9
#define ERR_TA_SWB_FILE_READ_FAILED        ERR_TA_SWB_BASE + (int32_t) -10
#define ERR_TA_SWB_RESOURCE_UNLOADED       ERR_TA_SWB_BASE + (int32_t) -11
#define ERR_TA_SWB_CIPHER_MODE_INVALID     ERR_TA_SWB_BASE + (int32_t) -12
#define ERR_TA_SWB_OUTPUT_SIZE_INVALID     ERR_TA_SWB_BASE + (int32_t) -20

#define ERR_SRKWB_BASE                     ERR_BASE + (int32_t) -3500
// -1 ~ -6 are reserved by waes_client_api.h

#define ERR_TA_SRKWB_BASE                  ERR_BASE + (int32_t) -3510
// -1 ~ -6 are reserved by waes_client_api.h

#define ERR_TA_X509_PARSE_BASE             ERR_BASE + (int32_t) -4000
// -1 ~ -15 are reserved by x509_parser_error_t at x509v3.h.

#define ERR_BASE_VENDOR                    ERR_BASE + (int32_t) -5000
#define ERR_COMMON_NOT_SUPPORT_CMD         ERR_BASE_VENDOR + (int32_t) -1
#define ERR_COMMON_INVALID_ARGUMENT        ERR_BASE_VENDOR + (int32_t) -2
#define ERR_COMMON_MALLOC_FAILED           ERR_BASE_VENDOR + (int32_t) -3
#define ERR_COMMON_BUFFER_OVERFLOW         ERR_BASE_VENDOR + (int32_t) -4
#define ERR_COMMON_SYSCALL_FAILED          ERR_BASE_VENDOR + (int32_t) -5
#define ERR_COMMON_ASYNC_FUNC              ERR_BASE_VENDOR + (int32_t) -6
#define ERR_COMMON_FUNC_TIMEOUT            ERR_BASE_VENDOR + (int32_t) -7
#define ERR_INVALID_VK_DRK_BLOB_LENGTH     ERR_BASE_VENDOR + (int32_t) -8
#define ERR_INVALID_VK_DRK_MAGIC           ERR_BASE_VENDOR + (int32_t) -9
#define ERR_INVALID_VK_DRK_DATA            ERR_BASE_VENDOR + (int32_t) -10

//#define ERR_ASN1_BASE   ERR_BASE_VENDOR | 0x1000
//#define ERR_UTIL_BASE   ERR_BASE_VENDOR | 0x2000
#define ERR_FILE_BASE                      ERR_BASE_VENDOR + (int32_t) -400
#define ERR_FILE_WRITE                     ERR_FILE_BASE   + (int32_t) -1
#define ERR_FILE_READ                      ERR_FILE_BASE   + (int32_t) -2
#define ERR_FILE_NOT_OPEN                  ERR_FILE_BASE   + (int32_t) -3
#define ERR_FILE_STAT_FAILED               ERR_FILE_BASE   + (int32_t) -4
#define ERR_FILE_SIZE_ZERO                 ERR_FILE_BASE   + (int32_t) -5
#define ERR_FILE_SYNC_FAILED               ERR_FILE_BASE   + (int32_t) -6
#define ERR_FILE_NOT_CHMOD                 ERR_FILE_BASE   + (int32_t) -7

#define ERR_TA_QSEE_BASE                   ERR_BASE + (int32_t) -10000
#define ERR_TA_BF_BASE                     ERR_TA_QSEE_BASE
// -73 ~ -95 are reserved by qsee_message.h

//SecureHW error
#define ERR_BASE_HERMES                    ERR_BASE + (int32_t) -20000
#define ERR_HERMES_SELFTEST_FAILED         ERR_BASE_HERMES + (int32_t) -1
#define ERR_HERMES_CRYPTO_UPDATE_FAIED     ERR_BASE_HERMES + (int32_t) -2

//It depends on 'drk.go' and 'prov/Android.mk'
#define ERR_DRK_DISABLE_BASE             ERR_BASE + (int32_t) -80000
#define ERR_TZ_DISABLE                   ERR_DRK_DISABLE_BASE + (int32_t) -1
#define ERR_SECUREBOOT_DSIABLE           ERR_DRK_DISABLE_BASE + (int32_t) -2
#define ERR_SECOND_BRAND                 ERR_DRK_DISABLE_BASE + (int32_t) -3
#endif
