/**
 * Copyright (C) 2011 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * Mobile Communication Division,
 * Digital Media & Communications Business, Samsung Electronics Co., Ltd.
 *
 * This software and its documentation are confidential and proprietary
 * information of Samsung Electronics Co., Ltd.  No part of the software and
 * documents may be copied, reproduced, transmitted, translated, or reduced to
 * any electronic medium or machine-readable form without the prior written
 * consent of Samsung Electronics.
 *
 * Samsung Electronics makes no representations with respect to the contents,
 * and assumes no responsibility for any errors that might appear in the
 * software and documents. This publication and the contents hereof are subject
 * to change without notice.
 *
 */

 /**
 * @file tz_hdcp2_common.h
 * @author
 * @date
 * @brief This file has all the common definitions and structure definitions used everywhere in the whole system.
 */
#ifndef _HDCP2_COMMON_H_
#define _HDCP2_COMMON_H_

#ifdef __cplusplus
extern "C"
{
#endif

/**
 * @def LC_128_SIZE
 *
 * This macro is assigned a value of 16, which specifies the size.
 *
 */
#define LC_128_SIZE	16

/**
 * @def HDCP2_MESSAGE_DIGEST_SIZE
 *
 * This macro is assigned a value of 32, which specifies the message digest size
 *
 */
#define HDCP2_MESSAGE_DIGEST_SIZE	32

/**
 * @def HDCP2_PAIR_INFO_PATH_LEN
 *
 * This macro is assigned a value of 256, which specifies the pair info path length.
 *
 */
#define HDCP2_PAIR_INFO_PATH_LEN	256


#define HDCP2_NO_TIME_LIMIT

typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long long u64;

// v0.1 change uuid

/**
 * @def HDCP2_VERSION
 *
 * This macro is assigned a value of hdcp v0.2, which specifies the hdcp version.
 *
 */
#define HDCP2_VERSION	"hdcp v0.2"

/**
 * @def MAX_ENCRYPT_BUFFER
 *
 * This macro is assigned a value about contiguous buffer size for encryption/decryption
 *
 */
#ifdef USE_4KMIRRORING
#define MAX_ENCRYPT_BUFFER	0x00280000 // 2.5MB
#else
#define MAX_ENCRYPT_BUFFER	0x00100000 // 1MB
#endif /* USE_4KMIRRORING */

/**
 * @def MAX_ENCRYPT_BUFFER_BL
 *
 * This macro is assigned a value of (MAX_ENCRYPT_BUFFER/16) to be maintained everywhere
 *
 */
#define MAX_ENCRYPT_BUFFER_BL	(MAX_ENCRYPT_BUFFER/16)

/**
 * @def MAX_INPUT_LENTH
 *
 * This macro is assigned a value of 0x00040000 to be maintained everywhere
 *
 */
#define MAX_INPUT_LENTH	0x00040000

/**
 * @def MAX_INCREASE_BUFFER
 *
 * This macro is assigned a value of 255 to be maintained everywhere
 *
 */
#define MAX_INCREASE_COUNTER	255

/**
 * @def MAX_HASH_BUFFER
 *
 * This macro is assigned a value of 256 to be maintained everywhere
 *
 */
#define MAX_HASH_BUFFER	256

/**
 * @def HDCP2_BUFFER_LEN
 *
 * This macro is assigned a value of (64*1024) to maintain buffer length everywhere
 *
 */
#define HDCP2_BUFFER_LEN	(64*1024)

/**
 * @def HDCP2_ENCRYPT
 *
 * This macro is assigned a value of 100 to specify encryption option.
 *
 */
#define HDCP2_ENCRYPT	100

/**
 * @def HDCP2_DECRYPT
 *
 * This macro is assigned a value of 200 to to specify decryption option.
 *
 */
#define HDCP2_DECRYPT	200
// TrustLet UUID

/**
 * @def TL_HDCP2_TRANSMITTER_UUID
 *
 * This macro is assigned the values which specifies the trustlet transmitter UUID
 *
 */
#define TL_HDCP2_TRANSMITTER_UUID {{0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4}}

/**
 * @def TL_HDCP2_RECEIVER_UUID
 *
 * This macro is assigned the values which specifies the trustlet receiver UUID
 *
 */
#define TL_HDCP2_RECEIVER_UUID {{0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5}}

/**
 * @def PROVISIONING_KEY_SIZE
 *
 * This macro is assigned a value of 880 to maintain provisioning key size when USE_MOBICORE is defined
 *
 */
#define PROVISIONING_KEY_SIZE	880

#ifdef USE_QUALCOMM
/**
 * @def PROVISIONING_KEY_SIZE
 *
 * This macro is assigned a value of 1100 to maintain wrapped key size when USE_MOBICORE is defined
 *
 */
#define WRAPPED_KEY_SIZE	1100
#else /* USE_QUALCOMM */
/**
 * @def PROVISIONING_KEY_SIZE
 *
 * This macro is assigned a value of 1008 to maintain wrapped key size when USE_MOBICORE is not defined
 *
 */
#define WRAPPED_KEY_SIZE	1008
#endif /* USE_QUALCOMM */

#ifdef CONFIG_HDCP_64BIT
/**
 * @def ADJUST_POINTER_SIZE
 *
 * This macro is assigned a value of 4 to adjust pointer size when CONFIG_HDCP_64BIT is defined
 * u8* size is 8bytes with 64bit machine but it has 4 bytes size on nwd because it is 32bit machine
 * So it should be adjusted on swd side
 *
 */
#define ADJUST_POINTER_SIZE 4
#else
/**
 * @def ADJUST_POINTER_SIZE
 *
 * This macro is assigned a value of 0 to adjust pointer size when CONFIG_HDCP_64BIT is not defined
 *
 */
#define ADJUST_POINTER_SIZE 0
#endif /* CONFIG_HDCP_64BIT */

/**
 * @def HDCP2_TZ_OK
 *
 * This macro is assigned a value of 0 to indicate no error.
 *
 */
#define HDCP2_TZ_OK	0

/**
 * @def HDCP2_TZ_NULL_RESPONSE
 *
 * This macro is assigned a value of -1 to indicate upstream shutdown.
 *
 */
#define HDCP2_TZ_NULL_RESPONSE	-1

/**
 * @def HDCP2_TZ_NULL_REQUEST
 *
 * This macro is assigned a value of -2 to indicate upstream shutdown.
 *
 */
#define HDCP2_TZ_NULL_REQUEST	-2

/**
 * @def HDCP2_TZ_CRYPTO_ERROR
 *
 * This macro is assigned value of -3 to indicate TrustZone crypt error.
 *
 */
#define HDCP2_TZ_CRYPTO_ERROR	-3

/**
 * @def HDCP2_AKE_MAX_TRIES
 *
 * This macro is assigned value of 16 which specifies the maximum trial for AKE connect.
 *
 */
#define HDCP2_AKE_MAX_TRIES	16

/**
 * @def HDCP2_LC_MAX_TRIES
 *
 * This macro is assigned value of 16 which specifies the maximum trial for LC connect.
 *
 */
#define HDCP2_LC_MAX_TRIES	16/*1024*/

/**
 * @def HDCP2_SIZE_AKE_SEND_CERT
 *
 * This macro is assigned value of 524 to indicate size of AKE_Send_Cert message.
 *
 */
#define HDCP2_SIZE_AKE_SEND_CERT	524

/**
 * @def HDCP2_SIZE_AKE_RECEIVER_INFO
 *
 * This macro is assigned value of 6 to indicate size of AKE_Receiver_Info message.
 *
 */
#define HDCP2_SIZE_AKE_RECEIVER_INFO	6

/**
 * @def HDCP2_SIZE_AKE_SEND_RRX
 *
 * This macro is assigned value of 9 to indicate size of AKE_Send_rrx message received from receiver.
 *
 */
#define HDCP2_SIZE_AKE_SEND_RRX	9

/**
 * @def HDCP2_SIZE_AKE_SEND_H_PRIME
 *
 * This macro is assigned value of 33 to indicate size of AKE_Send_H_Prime message.
 *
 */
#define HDCP2_SIZE_AKE_SEND_H_PRIME	33

/**
 * @def HDCP2_SIZE_AKE_SEND_PAIRING_INFO
 *
 * This macro is assigned value of 17 to indicate size of AKE_Send_Pairing_Info message.
 *
 */
#define HDCP2_SIZE_AKE_SEND_PAIRING_INFO	17

/**
 * @def HDCP2_SIZE_EXTRA_BUFFER_SIZE
 *
 * This macro is assigned value of 175 to indicate size of HDCP2_SIZE_EXTRA_BUFFER_SIZE.
 *
 */
#define HDCP2_SIZE_EXTRA_BUFFER_SIZE	176

/**
 * @def HDCP2_SIZE_LC_SEND_L_PRIME
 *
 * This macro is assigned value of 33 to indicate size of LC_Send_L_prime message.
 *
 */
#define HDCP2_SIZE_LC_SEND_L_PRIME	33

/**
 * @def HDCP2_SIZE_RECEIVER_PUBKEY
 *
 * This macro is assigned value of 128 to indicate size of Receiver's public key.
 *
 */
#define HDCP2_SIZE_RECEIVER_PUBKEY	128

/**
 * @def HDCP2_VERSION_2_0
 *
 * This macro is assigned a value of 20 to be maintained everywhere and it specifies the version of HDCP used.
 */
#define HDCP2_VERSION_2_0	20

/**
 * @def HDCP2_VERSION_2_1
 *
 * This macro is assigned a value of 21 to be maintained everywhere and it specifies the version of HDCP used.
 */
#define HDCP2_VERSION_2_1	21

/**
 * @def HDCP2_VERSION_2_2
 *
 * This macro is assigned a value of 22 to be maintained everywhere and it specifies the version of HDCP used.
 */
#define HDCP2_VERSION_2_2	22

/**
 * @def HDCP2_VERSION_2_3
 *
 * This macro is assigned a value of 23 to be maintained everywhere and it specifies the version of HDCP used.
 */
#define HDCP2_VERSION_2_3	23

/**
 * @def RECIEVER_ID_SIZE
 *
 * This macro is assigned value of 5 to indicate size of Reciever_id in case of multiple Rx Support.
 *
 */
#define RECEIVER_ID_SIZE	5

/**
 * @def HDCP_FIXED_SIZE_REPEATERAUTH_SEND_RECEIVERID_LIST21
 *
 * This macro is assigned value of 26 to indicate size of RepeaterAuth_Send_ReceiverID_List_21 in case of multiple Rx Support.
 *
 */
#define HDCP_FIXED_SIZE_REPEATERAUTH_SEND_RECEIVERID_LIST21	26

/**
 * @def HDCP_FIXED_SIZE_REPEATERAUTH_SEND_RECEIVERID_LIST20
 *
 * This macro is assigned value of 37 to indicate fixed size of RepeaterAuth_Send_ReceiverID_List_20 in case of multiple Rx Support.
 *
 */
#define HDCP_FIXED_SIZE_REPEATERAUTH_SEND_RECEIVERID_LIST20	37

/**
 * @def HDCP_SIZE_REPEATERAUTH_SEND_RECEIVERID_LIST21
 *
 * This macro is assigned value of 31 to indicate size of RepeaterAuth_Send_ReceiverID_List message.
 *
 */
#define HDCP_SIZE_REPEATERAUTH_SEND_RECEIVERID_LIST21	181

/**
 * @def HDCP_SIZE_REPEATERAUTH_SEND_RECEIVERID_LIST20
 *
 * This macro is assigned value of 42 to indicate size of RepeaterAuth_Send_ReceiverID_List message.
 */
#define HDCP_SIZE_REPEATERAUTH_SEND_RECEIVERID_LIST20	192

/**
 * @def HDCP_SIZE_RECEIVERAUTH_STATUS
 *
 * This macro is assigned value 4 to indicate the size of Receiver_AuthStatus message.
 *
 */
#define HDCP_SIZE_RECEIVERAUTH_STATUS	4

/**
 * @def HDCP2_SIZE_RECEIVERAUTH_READY
 *
 * This macro is assigned value of 33 to indicate size of RepeaterAuth_Stream_Ready message.
 *
 */
#define HDCP2_SIZE_RECEIVERAUTH_READY	33

/**
 * @def LOG_TAG
 *
 * This macro is assigned value of "HDCP2" to be maintained everywhere
 *
 */
#define LOG_TAG "HDCP2"

/**
 * @def HDCP2_OK
 *
 * This macro is assigned value of 0 to indicate no error.
 */
#define HDCP2_OK	0

/**
 * @def HDCP2_ERR
 *
 * This macro is assigned value of -1 to indicate error.
 */
#define HDCP2_ERR	-1

/**
 * @def HDCP2_ERR_AKE_BASE
 *
 * This macro is assigned value of 0 to indicate error in AKE base.
 */
#define HDCP2_ERR_AKE_BASE	0

/**
 * @def HDCP2_ERR_INVALID_INPUT
 *
 * This macro is assigned value of -51 to indicate invalid input error.
 */
#define HDCP2_ERR_INVALID_INPUT	-51

/**
 * @def HDCP2_ERR_RECEIVER_CERT_SIGN_FAIL
 *
 * This macro is assigned value of -56 to indicate receiver certificate signing.
 */
#define HDCP2_ERR_RECEIVER_CERT_SIGN_FAIL	-56

/**
 * @def HDCP2_ERR_NOT_SUPPORTED_COMMAND
 *
 * This macro is assigned value of -52 to indicate error for command not supported.
 */
#define HDCP2_ERR_NOT_SUPPORTED_COMMAND	-52

/**
 * @def HDCP2_ERR_UNSUPPRTED_PARTY
 *
 * This macro is assigned value of -53 to indicate unsupported party error.
 */
#define HDCP2_ERR_UNSUPPRTED_PARTY	-53

/**
 * @def HDCP2_ERR_UNSUPPRTED_TZ
 *
 * This macro is assigned value of -54 to indicate unsupported TZ error.
 */
#define HDCP2_ERR_UNSUPPRTED_TZ	-54

/**
 * @def HDCP2_ERR_MAKE_PAIRING_DIR
 *
 * This macro is assigned value of -55 to indicate error in making pair.
 */
#define HDCP2_ERR_MAKE_PAIRING_DIR	-55

/**
 * @def HDCP2_ERR_DCP_VERIFICATION
 *
 * This macro is assigned value of -56 to indicate error in HDCP Receiver Cert fail
 */
#define HDCP2_ERR_DCP_VERIFICATION	-56

/**
 * @def HDCP2_ERR_SEND_PAIRING_INFO
 *
 * This macro is assigned value of -100 to indicate error in AKE_Send_Pairing_Info.
 */
#define HDCP2_ERR_SEND_PAIRING_INFO	-100

/**
 * @def HDCP2_ERR_WRITE_PAIRING_INFO1
 *
 * This macro is assigned value of -101 to indicate error in opening pair_info_path in HDCP2_Store_Pairing_Info while writing.
 */
#define HDCP2_ERR_WRITE_PAIRING_INFO1	-101

/**
 * @def HDCP2_ERR_WRITE_PAIRING_INFO2
 *
 * This macro is assigned value of -102 to indicate error in writing encrypted paiting info.
 */
#define HDCP2_ERR_WRITE_PAIRING_INFO2	-102

/**
 * @def HDCP2_ERR_WRITE_PAIRING_INFO3
 *
 * This macro is assigned value of -103 to be maintained everywhere.
 */
#define HDCP2_ERR_WRITE_PAIRING_INFO3	-103

/**
 * @def HDCP2_ERR_SET_PAIRING_INFO
 *
 * This macro is assigned value of -110 to indicate error in setting pairing info.
 */
#define HDCP2_ERR_SET_PAIRING_INFO	-110

/**
 * @def HDCP2_ERR_LOAD_PAIRING_INFO1
 *
 * This macro is assigned value of -120 to indicate error in opening pair_info_path in HDCP2_Store_Pairing_Info while reading.
 */
#define HDCP2_ERR_LOAD_PAIRING_INFO1	-120

/**
 * @def HDCP2_ERR_LOAD_PAIRING_INFO2
 *
 * This macro is assigned value of -121 to indicate error in reading encrypted paiting info.
 */
#define HDCP2_ERR_LOAD_PAIRING_INFO2	-121

/**
 * @def HDCP2_ERR_LOAD_PAIRING_INFO3
 *
 * This macro is assigned value of -122 to indicate error in loading encrypted pair info in TZ.
 */
#define HDCP2_ERR_LOAD_PAIRING_INFO3	-122

/**
 * @def HDCP2_ERR_INVALID_KEYBOX
 *
 * This macro is assigned value of -131 to indicate error in loading key.
 */
#define HDCP2_ERR_INVALID_KEYBOX	-131

/**
 * @def HDCP2_ERR_WRITE_WRAPPED_KEYBOX1
 *
 * This macro is assigned value of -132 to indicate error in opening path for wrap key for reading.
 */
#define HDCP2_ERR_WRITE_WRAPPED_KEYBOX1	-132

/**
 * @def HDCP2_ERR_WRITE_WRAPPED_KEYBOX2
 *
 * This macro is assigned value of -133 to indicate error in reading the wrap key.
 */
#define HDCP2_ERR_WRITE_WRAPPED_KEYBOX2	-133

/**
 * @def HDCP2_ERR_WRITE_WRAPPED_KEYBOX3
 *
 * This macro is assigned value of -134 to indicate error in opening path for wrap key for writing.
 */
#define HDCP2_ERR_WRITE_WRAPPED_KEYBOX3	-134

/**
 * @def HDCP2_ERR_WRITE_WRAPPED_KEYBOX4
 *
 * This macro is assigned value of -135 to indicate error in writing the wrap key.
 */
#define HDCP2_ERR_WRITE_WRAPPED_KEYBOX4	-135

/**
 * @def HDCP2_ERR_WRITE_WRAPPED_KEYBOX5
 *
 * This macro is assigned value of -136 to indicate error in opening path for wrap key for wiping redata.bin
 */
#define HDCP2_ERR_WRITE_WRAPPED_KEYBOX5	-136

/**
 * @def HDCP2_ERR_WRITE_WRAPPED_KEYBOX6
 *
 * This macro is assigned value of -137 to be maintained everywhere.
 */
#define HDCP2_ERR_WRITE_WRAPPED_KEYBOX6	-137

/**
 * @def HDCP2_ERR_WRAP_KEYBOX1
 *
 * This macro is assigned value of -140 to be maintained everywhere.
 */
#define HDCP2_ERR_WRAP_KEYBOX1	-140

/**
 * @def HDCP2_ERR_WRAP_KEYBOX2
 *
 * This macro is assigned value of -141 to be maintained everywhere.
 */
#define HDCP2_ERR_WRAP_KEYBOX2	-141

/**
 * @def HDCP2_ERR_WRAP_KEYBOX3
 *
 * This macro is assigned value of -142 to be maintained everywhere.
 */
#define HDCP2_ERR_WRAP_KEYBOX3	-142

/**
 * @def HDCP2_ERR_READ_WRAPPED_KEYBOX1
 *
 * This macro is assigned value of -145 to indicate error in opening wrappedkey path.
 */
#define HDCP2_ERR_READ_WRAPPED_KEYBOX1	-145

/**
 * @def HDCP2_ERR_READ_WRAPPED_KEYBOX2
 *
 * This macro is assigned value of -146 to indicate error in reading wrappedkey.
 */
#define HDCP2_ERR_READ_WRAPPED_KEYBOX2	-146

/**
 * @def HDCP2_ERR_INVALID_H
 *
 * This macro is assigned value of -201 to indicate error in case of invalid H value in AKE_Send_H_prime message.
 */
#define HDCP2_ERR_INVALID_H	-201

/**
 * @def HDCP2_ERR_INVALID_L
 *
 * This macro is assigned value of -202 to indicate error in case of invalid L value in LC_Send_L_prime message.
 */
#define HDCP2_ERR_INVALID_L	-202

/**
 * @def HDCP2_ERR_STORED_KM_NOT_PAIRED
 *
 * This macro is assigned value of -203 to indicate error if Stored KM is not paired.
 */
#define HDCP2_ERR_STORED_KM_NOT_PAIRED	-203

/**
 * @def HDCP2_ERR_REAUTH_REQ
 *
 * This macro is assigned value of -204 to indicate signal if Repeater Asks for Reauthentication.
 */
#define HDCP2_ERR_REAUTH_REQ	-204

/**
 * @def HDCP2_ERR_INVALID_V
 *
 * This macro is assigned value of -205 to indicate error if v is not equal to V'.
 */
#define HDCP2_ERR_INVALID_V	-205

/**
 * @def HDCP2_ERR_TIME_REPEATER_RECEIVER_ID
 *
 * This macro is assigned value of -206 to be maintained everywhere.
 */
#define HDCP_ERR_TIME_REPEATER_RECEIVER_ID	-206

/**
 * @def HDCP2_ERR_SRM_CHECK_FAIL
 *
 * This macro is assigned value of -207 to indicate error in SRM_Check.
 */
#define HDCP_ERR_SRM_CHECK_FAIL	-207

/**
 * @def HDCP2_ERR_NO_SRM_FILE
 *
 * This macro is assigned value of -208 to indicate error in opening SRM file.
 */
#define HDCP_ERR_NO_SRM_FILE	-208

/**
 * @def HDCP2_ERR_SRM_BUFFER_MEMORY_FAIL
 *
 * This macro is assigned value of -209 to indicate error in memory allocation.
 */
#define HDCP_ERR_SRM_BUFFER_MEMORY_FAIL	-209

/**
 * @def HDCP2_ERR_INVALID_M
 *
 * This macro is assigned value of -210 to indicate error in case of invalid M value.
 */
#define HDCP2_ERR_INVALID_M	-210

/**
 * @def HDCP2_ERR_MAX_STREAM_EXCEEDED
 *
 * This macro is assigned value of -211 to indicate Max stream exceeded in HDCP2_DownstreamPropagation.
 */
#define HDCP2_ERR_TIMEDOUT_M	-211

/**
 * @def HDCP2_ERR_TOO_MANY_DEVICES
 *
 * This macro is assigned value of -216 to indicate of HDCP2_ERR_TOO_MANY_DEVICES.
 */
#define HDCP2_ERR_TOO_MANY_DEVICES	-216

/**
 * @def HDCP2_ERR_TIME_AKE_RECEIVER_INFO
 *
 * This macro is assigned value of -301 to indicate AKE_RECEIVER_INFO timeout.
 */
#define HDCP2_ERR_TIME_AKE_RECEIVER_INFO	-301

/**
 * @def HDCP2_ERR_TIME_AKE_SEND_H_PRIME
 *
 * This macro is assigned value of -302 to indicate AKE_SEND_H_PRIME timeout.
 */
#define HDCP2_ERR_TIME_AKE_SEND_H_PRIME	-302

/**
 * @def HDCP2_ERR_TIME_AKE_SEND_PAIRING_INFO
 *
 * This macro is assigned value of -303 to indicate AKE_SEND_PAIRING_INFO timeout.
 */
#define HDCP2_ERR_TIME_AKE_SEND_PAIRING_INFO	-303

/**
 * @def HDCP2_ERR_TIME_LC_SEND_L_PRIME
 *
 * This macro is assigned value of -304 to indicate LC_SEND_L_PRIME timeout.
 */
#define HDCP2_ERR_TIME_LC_SEND_L_PRIME	-304

/**
 * @def HDCP2_ERR_VERI_SKE
 *
 * This macro is assigned value of -308 to indicate Compare HMAC fail in SKE_Send_Eks.
 */
#define HDCP2_ERR_VERI_SKE	-308

/**
 * @def HDCP2_ERR_AKE
 *
 * This macro is assigned value of -310 to indicate error in AKE.
 */
#define HDCP2_ERR_AKE	-310

/**
 * @def HDCP2_ERR_LC
 *
 * This macro is assigned value of -311 to indicate error in Locality Check.
 */
#define HDCP2_ERR_LC	-311

/**
 * @def HDCP2_ERR_CRYPTO
 *
 * This macro is assigned value of -401 to indicate error in encryption-decryption.
 */
#define HDCP2_ERR_CRYPTO	-401

/**
 * @def HDCP2_ERR_OAEP_ENCRYPTION
 *
 * This macro is assigned value of -402 to indicate error in OAEP encryption.
 */
#define HDCP2_ERR_OAEP_ENCRYPTION	-402

/**
 * @def HDCP2_ERR_OAEP_DECRYPTION
 *
 * This macro is assigned value of -403 to indicate error in OAEP decryption.
 */
#define HDCP2_ERR_OAEP_DECRYPTION	-403

/**
 * @def HDCP2_ERR_KDF
 *
 * This macro is assigned value of -404 to indicate error in KDF function.
 */
#define HDCP2_ERR_KDF	-404

/**
 * @def HDCP2_ERR_NULL_POINTER
 *
 * This macro is assigned value of -500 to indicate error in case of null pointer.
 */
#define HDCP2_ERR_NULL_POINTER	-500

/**
 * @def HDCP2_ERR_NULL_REQUEST
 *
 * This macro is assigned value of -501 to indicate error in case of null request.
 */
#define HDCP2_ERR_NULL_REQUEST	-501

/**
 * @def HDCP2_ERR_NULL_RESPONSE
 *
 * This macro is assigned value of -502 to indicate error in case of null response.
 */
#define HDCP2_ERR_NULL_RESPONSE	-502

/**
 * @def HDCP2_NETWORK_ERROR
 *
 * This macro is assigned value of -600 to indicate network error.
 */
#define HDCP2_NETWORK_ERROR	-600

/**
 * @def HDCP2_ERR_TRUSTZONE_OPEN
 *
 * This macro is assigned value of -650 to indicate error in opening trustzone.
 */
#define HDCP2_ERR_TRUSTZONE_OPEN	-650


/**
 * @def HDCP2_ERR_TRUSTZONE_BASE
 *
 * This macro is assigned value of -1000 to indicate error in tlApiCipher
 */
#define HDCP2_ERR_TRUSTZONE_BASE	-1000

/**
 * @def HDCP2_ERR_TRUSTZONE_DECODE_KEY
 *
 * This macro is assigned value of -1099 to indicate error in TZ key decode.
 */
#define HDCP2_ERR_TRUSTZONE_DECODE_KEY	-1099

/**
 * @def HDCP2_ERR_HW_INIT
 *
 * This macro is assigned value of -1100 to indicate error in HW init.
 */
#define HDCP2_ERR_HW_INIT	-1100

/**
 * @def HDCP2_ERR_HW_TERMINATE
 *
 * This macro is assigned value of -1101 to indicate [HDCP2]Sec Finalization error.
 */
#define HDCP2_ERR_HW_TERMINATE	-1101

/**
 * @def HDCP2_ERR_HW_ATTACH_CRYPTO
 *
 * This macro is assigned value of -1102 to indicate [HDCP2]Sec H/W attach error.
 */
#define HDCP2_ERR_HW_ATTACH_CRYPTO	-1102

/**
 * @def HDCP2_ERR_HW_DETTACH_CRYPTO
 *
 * This macro is assigned value of -1103 to indicate [HDCP2]Sec H/W detach error.
 */
#define HDCP2_ERR_HW_DETTACH_CRYPTO	-1103

/**
 * @def HDCP2_ERR_HW_CRYPTO
 *
 * This macro is assigned value of -1104 to indicate HW encryption-decryption failure.
 */
#define HDCP2_ERR_HW_CRYPTO	-1104

/**
 * @def HDCP2_ERR_DRM_SET_HDCP2_MAGICKEY
 *
 * This macro is assigned value of -1200 to indicate error in setting HDCP2 MagicKey.
 */
#define HDCP2_ERR_DRM_SET_HDCP2_MAGICKEY	-1200

/**
 * @def HDCP2_ERR_GET_OEM_FLAG
 *
 * This macro is assigned value of -1301 to indicate HDCP2_GetOemFlag Failure.
 */
#define HDCP2_ERR_GET_OEM_FLAG	-1301

/**
 * @def HDCP2_ERR_SET_OEM_FLAG
 *
 * This macro is assigned value of -1302 to indicate HDCP2_SetOemFlag Failure.
 */
#define HDCP2_ERR_SET_OEM_FLAG	-1302

/**
 * @def HDCP2_ERR_SET_HDCP2_FLAG
 *
 * This macro is assigned value of -1303 to indicate [HDCP2]Sec tlApiSecSetHdcp2Flag error.
 */
#define HDCP2_ERR_SET_HDCP2_FLAG	-1303

/**
 * @def HDCP2_ERR_INTEGRITY
 *
 * This macro is assigned value of -1310 to indicate error in integrity.
 */
#define HDCP2_ERR_INTEGRITY	-1310

/**
 * @def HDCP2_ERR_SECBOOT_DISABLED
 *
 * This macro is assigned value of -1311 to indicate error in SecureBoot disabled.
 */
#define HDCP2_ERR_SECBOOT_DISABLED	-1311

/**
 * @def HDCP2_NOT_VALID_CIPER_MODE
 *
 * This macro is assigned value of -10000 to indicate invalid cipher mode.
 */
#define HDCP2_NOT_VALID_CIPER_MODE	-10000

/**
 * @def HDCP2_VALID_TIME_100MS
 *
 * This macro is assigned value of 100 to indicate 100ms time constraint
 */
#define HDCP2_VALID_TIME_100MS	100 // 100ms

/**
 * @def HDCP2_VALID_TIME_200MS
 *
 * This macro is assigned value of 200 to check AKE_Send_H_prime timeout in case of stored Km.
 */
#define HDCP2_VALID_TIME_200MS	200 // 200ms

/**
 * @def HDCP2_VALID_TIME_1SEC
 *
 * This macro is assigned value of 1000 to check AKE_Send_H_prime timeout in case of No stored Km.
 */
#define HDCP2_VALID_TIME_1SEC	1000  // 1sec

/**
 * @def HDCP2_VALID_TIME_7MS
 *
 * This macro is assigned value of 7 to check LC_Send_L_prime timeout.
 */
#define HDCP2_VALID_TIME_7MS	7 //7ms

/**
 * @def HDCP2_VALID_TRAILS_LC_INIT
 *
 * This macro is assigned value of 1024 to indicate number of valid Locality Check trials.
 */
#define HDCP2_VALID_TRAILS_LC_INIT	1024

/**
 * @def HDCP_REPEATER_RECEIVER_ID_DURATION
 *
 * This macro is assigned value of 3000 to indicate duration for Repeater ReceiverID.
 */
#define HDCP2_REPEATER_RECEIVER_ID_DURATION	3000 //3 sec

/**
 * @def HDCP2_ERR_BUFFER_PROTECTION
 *
 * This macro is assigned value of -1304 to indicate tlApi_tzbsp_core_is_stag_area non secure memory.
 */
#define HDCP2_ERR_BUFFER_PROTECTION	-1304

/**
 * @def SFS_FILE_OPEN_FAIL
 *
 * This macro is assigned value of -1246 to indicate failure in opening SFS file.
 */
#define SFS_FILE_OPEN_FAIL	-1246

/**
 * @def SFS_DIR_MAKE_FAIL
 *
 * This macro is assigned value of -1247 to indicate failure in making SFS directory.
 */
#define SFS_DIR_MAKE_FAIL	-1247

/**
 * @def KEY_VERIFICATION_FAILED
 *
 * This macro is assigned value of -1248 to indicate failure in key verification.
 */
#define KEY_VERIFICATION_FAILED	-1248

/**
 * @def HDCP2_TYPE1_CONTENT
 *
 * This macro is assigned value of -1332 to indicate type 1 stream
 */
#define HDCP2_TYPE1_CONTENT	-1332

/**
 * @def HDCP2_TYPE0_CONTENT
 *
 * This macro is assigned value of -1333 to indicate type 0 stream.
 */
#define HDCP2_TYPE0_CONTENT	-1333

/**
 * @def CMD_TRANSMITTER
 *
 * This macro is assigned value of 100 to be maintained everywhere as Transmitter command.
 */
#define CMD_TRANSMITTER	100

/**
 * @def CMD_RECEIVER
 *
 * This macro is assigned value of 200 to be maintained everywhere as Receiver command.
 */
#define CMD_RECEIVER	200

// 4.2 Control/Status Stream (msg_id), HDCP 2.1 spec, pp.56
/**
 * @def CMD_NULL_MESSAGE
 *
 * This macro is assigned value of 1 to indicate null message command.
 */
#define CMD_NULL_MESSAGE	1

/**
 * @def CMD_AKE_INIT
 *
 * This macro is assigned value of 2 to indicate AKE_Init command.
 */
#define CMD_AKE_INIT	2

/**
 * @def CMD_AKE_SEND_CERT
 *
 * This macro is assigned value of 3 to indicate AKE_Send_Cert command.
 */
#define CMD_AKE_SEND_CERT	3

/**
 * @def CMD_AKE_NO_STORED_KM
 *
 * This macro is assigned value of 4 to indicate AKE_No_Stored_Km command.
 */
#define CMD_AKE_NO_STORED_KM	4

/**
 * @def CMD_AKE_STORED_KM
 *
 * This macro is assigned value of 5 to indicate AKE_Stored_Km command.
 */
#define CMD_AKE_STORED_KM	5

/**
 * @def CMD_AKE_SEND_RRX
 *
 * This macro is assigned value of 6 to indicate AKE_Send_rrx command.
 */
#define CMD_AKE_SEND_RRX	6

/**
 * @def CMD_AKE_SEND_H_PRIME
 *
 * This macro is assigned value of 7 to indicate AKE_Send_H_prime command.
 */
#define CMD_AKE_SEND_H_PRIME	7

/**
 * @def CMD_AKE_SEND_PAIRING_INFO
 *
 * This macro is assigned value of 8 to indicate AKE_Send_Pairing_Info command.
 */
#define CMD_AKE_SEND_PAIRING_INFO	8

/**
 * @def CMD_LC_INIT
 *
 * This macro is assigned value of 9 to indicate LC_Init command.
 */
#define CMD_LC_INIT	9

/**
 * @def CMD_LC_SEND_L_PRIME
 *
 * This macro is assigned value of 10 to indicate LC_Send_L_Prime command.
 */
#define CMD_LC_SEND_L_PRIME	10

/**
 * @def CMD_SKE_SEND_EKS
 *
 * This macro is assigned value of 11 to indicate SKE_Send_Eks command.
 */
#define CMD_SKE_SEND_EKS	11

/**
 * @def CMD_REPEATERAUTH_SEND_RECEIVER_ID_LIST
 *
 * This macro is assigned value of 12 to indicate RepeaterAuth_Send_ReceiverID_list command.
 */
#define CMD_REPEATERAUTH_SEND_RECEIVER_ID_LIST	12

/**
 * @def CMD_RTT_READY
 *
 * This macro is assigned value of 13 to indicate RTT_Ready command.
 */
#define CMD_RTT_READY	13

/**
 * @def CMD_RTT_CHALLENGE
 *
 * This macro is assigned value of 14 to indicate RTT_Challenge command.
 */
#define CMD_RTT_CHALLENGE	14

/**
 * @def CMD_REPEATERAUTH_SEND_ACK
 *
 * This macro is assigned value of 15 to indicate RepeaterAuth_Send_Ack command.
 */
#define CMD_REPEATERAUTH_SEND_ACK	15

/**
 * @def CMD_REPEATERAUTH_STREAM_MANAGE
 *
 * This macro is assigned value of 16 to indicate RepeaterAuth_Stream_Manage command.
 */
#define CMD_REPEATERAUTH_STREAM_MANAGE	16

/**
 * @def CMD_REPEATERAUTH_STREAM_READY
 *
 * This macro is assigned value of 17 to indicate RepeaterAuth_Stream_Ready command.
 */
#define CMD_REPEATERAUTH_STREAM_READY	17

/**
 * @def CMD_RECEIVER_AUTHSTATUS
 *
 * This macro is assigned value of 18 to indicate Repeater_AuthStatus command.
 */
#define CMD_RECEIVER_AUTHSTATUS	18

/**
 * @def CMD_AKE_TRANSMITTER_INFO
 *
 * This macro is assigned value of 19 to indicate AKE_Transmitter_Info command.
 */
#define CMD_AKE_TRANSMITTER_INFO	19

/**
 * @def CMD_AKE_RECEIVER_INFO
 *
 * This macro is assigned value of 20 to indicate AKE_Receiver_Info command.
 */
#define CMD_AKE_RECEIVER_INFO	20

/**
 * @def CMD_CIP_ENC_DATA
 *
 * This macro is assigned value of 21 to indicate CIP_ENC_Data command.
 */
#define CMD_CIP_ENC_DATA	21

/**
 * @def CMD_CIP_DEC_DATA
 *
 * This macro is assigned value of 22 to indicate CIP_DEC_Data command.
 */
#define CMD_CIP_DEC_DATA	22

// Custom command
/**
 * @def CMD_CIP_SPS_PPS_DATA
 *
 * This macro is assigned value of 26 to indicate CIP_SPS_PPS_Data command.
 */
#define CMD_CIP_SPS_PPS_DATA	26

/**
 * @def CMD_HDCP2_LOADKEY_ODM
 *
 * This macro is assigned value of 49 to indicate HDCP2_LoadKey command for ODM.
 */
#define CMD_HDCP2_LOADKEY_ODM	49

/**
 * @def CMD_AKE_SET_PAIRING_INFO
 *
 * This macro is assigned value of 50 to indicate AKE_Set_Pairing_Info command.
 */
#define CMD_AKE_SET_PAIRING_INFO	50

/**
 * @def CMD_HDCP2_WRAPKEY
 *
 * This macro is assigned value of 51 to indicate HDCP2_WrapKey command.
 */
#define CMD_HDCP2_WRAPKEY	51

/**
 * @def CMD_HDCP2_LOADKEY
 *
 * This macro is assigned value of 52 to indicate HDCP2_LoadKey command.
 */
#define CMD_HDCP2_LOADKEY	52

/**
 * @def CMD_CIP_DEC_DATA_ION
 *
 * This macro is assigned value of 53 to indicate CIP_DEC_Data_Ion command.
 */
#define CMD_CIP_DEC_DATA_ION	53

/**
 * @def CMD_HDCP2_STOREKEY
 *
 * This macro is assigned value of 54 to indicate HDCP2_StoreKey command.
 */
#define CMD_HDCP2_STOREKEY	54

/**
* @def CMD_SET_PROTOCOL_DESCRIPTOR
*
* This macro is assigned value of 27 to indicate SET_PROTOCOL_DESCRIPTOR command if HDCP version is 2.2
*/
#define CMD_SET_HDCP_VERSION	27

// Trustzone Init
/**
 * @def CMD_TRUSTZONE_INIT
 *
 * This macro is assigned value of 70 to indicate trustzone initialization.
 */
#define CMD_TRUSTZONE_INIT	70

/**
 * @def CMD_TRUSTZONE_CLOSE
 *
 * This macro is assigned value of 71 to indicate closure of trustzone.
 */
#define CMD_TRUSTZONE_CLOSE	71

/**
 * @def CMD_OEM_GET_FLAG
 *
 * This macro is assigned value of 80 to indicate OEM_GetFlag command.
 */
#define CMD_OEM_GET_FLAG	80

/**
 * @def CMD_OEM_SET_FLAG
 *
 * This macro is assigned value of 81 to indicate OEM_SetFlag command.
 */
#define CMD_OEM_SET_FLAG	81

/**
 * @def CMD_DRM_GET_MFC_MAGICKEY
 *
 * This macro is assigned value of 91 to indicate CMD_DRM_GET_MFC_MAGICKEY command.
 */
#define CMD_DRM_GET_MFC_MAGICKEY	91

/**
 * @def TRANSMITTER_LOCALITY_PRECOMPUTE_SUPPORT
 *
 * This macro is assigned value of 0x01 to be maintained everywhere.
 */
#define LOCALITY_PRECOMPUTE_SUPPORT	0x01

/**
 * @def TRANSMITTER_CONTENT_CATEGORY_SUPPORT
 *
 * This macro is assigned value of 0x02 to be maintained everywhere.
 */
#define CONTENT_CATEGORY_SUPPORT	0x02

/**
 * @def MAX_RECEIVER_DEVICE 
 *
 * This macro is assigned value of 31 to be maintained everywhere.
 */
#define MAX_RECEIVER_DEVICE	31

/**
 * @struct HDCP2_Receiver_Certificate_
 *
 * This structure contains information regarding receiver certificate.
 *
 */
typedef struct HDCP_Receiver_Certificate_ {
	u8 receiver_id[5];
	u8 publickey_n[HDCP2_SIZE_RECEIVER_PUBKEY];
	u8 publickey_e[3];
	u8 reserved_1:4;
	u8 Protocol_Descriptor:4;
	u8 reserved_2;
	u8 dcp_llc_sign[384];
} HDCP2_RECEIVER_CERTIFICATE;

/**
 * @struct RSA_PRIVATE_KEY_
 *
 * This structure contains information regarding rsa private key.
 */
typedef struct RSA_PRIVATE_KEY_ {
	u8 p[64];
	u8 q[64];
	u8 dmp1[64];
	u8 dmq1[64];
	u8 iqmp[64];
} RSA_PRIVATE_KEY;

/**
 * @struct HDCP2_KEY_
 *
 * This structure contains information regarding Device Key Set of Receiver.
 */
typedef struct HDCP2_KEY_ {
	u8 lc128[LC_128_SIZE];
	HDCP2_RECEIVER_CERTIFICATE cert;
	RSA_PRIVATE_KEY private_key;
	u8 ckey[16];
	u8 reserved[134];
} HDCP2_KEY;

/*
 * AKE Payloads
 *
 */

//4.3.1 AKE_Init(Transmitter to Receiver)
/**
 * @struct AKE_Init_
 *
 * This structure contains information regarding AKE_Init message.
 */
typedef struct AKE_Init_ {
	u8 msg_id;
	u8 rtx[8];
} AKE_INIT;

//4.3.2 AKE_Send_cert(Receiver to Transmitter)
/**
 * @struct AKE_Send_cert_
 *
 * This structure contains information regarding AKE_Send_Cert message.
 */
typedef struct AKE_Send_cert_ {
	u8 msg_id;
	u8 REPEATER;
	u8 certrx[522];
} AKE_SEND_CERT;

//4.3.3 AKE_No_Stored_km(Transmitter to Receiver)
/**
 * @struct AKE_No_Stored_km_
 *
 * This structure contains information regarding AKE_No_Stored_km message.
 */
typedef struct AKE_No_Stored_km_ {
	u8 msg_id;
	u8 Ekpub_km[HDCP2_SIZE_RECEIVER_PUBKEY];
} AKE_NO_STORED_KM;

//4.3.4 AKE_Stored_km(Transmitter to Receiver)
/**
 * @struct AKE_STORED_KM
 *
 * This structure contains information regarding AKE_Stored_km message.
 */
typedef struct AKE_Stored_km_ {
	u8 msg_id;
	u8 Ekh_km[16];
	u8 m[16];
} AKE_STORED_KM;

//4.3.5 AKE_Send_rrx(Receiver to Transmitter)
/**
 * @struct AKE_Send_rrx_
 *
 * This structure contains information regarding AKE_Send_rrx message.
 */
typedef struct AKE_Send_rrx_ {
	u8 msg_id;
	u8 rrx[8];
} AKE_SEND_RRX;

//4.3.6 AKE_Send_H_prime(Receiver to Transmitter)
/**
 * @struct AKE_Send_H_prime_
 *
 * This structure contains information regarding AKE_Send_H_prime message.
 */
typedef struct AKE_Send_H_prime_ {
	u8 msg_id;
	u8 H[32];
} AKE_SEND_H_PRIME;

//4.3.7 AKE_Send_Pairing_Info(Receiver to Transmitter)
/**
 * @struct AKE_Send_Pairing_Info_
 *
 * This structure contains information regarding AKE_Send_Pairing_Info message.
 */
typedef struct AKE_Send_Pairing_Info_ {
	u8 msg_id;
	u8 Ekh_Km[16];
} AKE_SEND_PAIRING_INFO;

//4.3.18 AKE_Transmitter_Info(Transmitter to Receiver)
/**
 * @struct AKE_Transmitter_Info_
 *
 * This structure contains information regarding AKE_Transmitter_Info message.
 */
typedef struct AKE_Transmitter_Info_ {
	u8 msg_id;
	u8 LENGTH[2];
	u8 VERSION;
	u8 TRANSMITTER_CAPABILITY_MASK[2];
} AKE_TRANSMITTER_INFO;

//4.3.19 AKE_Receiver_Info(Receiver to Transmitter)
/**
 * @struct AKE_Receiver_Info_
 *
 * This structure contains information regarding AKE_Receiver_Info message.
 */
typedef struct AKE_Receiver_Info_ {
	u8 msg_id;
	u8 LENGTH[2];
	u8 VERSION;
	u8 RECEIVER_CAPABILITY_MASK[2];
} AKE_RECEIVER_INFO;

/**
 * @struct LC_Init_
 *
 * This structure contains information regarding LC_Init message.
 */
typedef struct LC_Init_ {
	u8 msg_id;
	u8 rn[8];
} LC_INIT;

/**
 * @struct RTT_Ready_
 *
 * This structure contains information regarding RTT_Ready message.
 */
typedef struct RTT_Ready_ {
	u8 msg_id;
} RTT_READY;

/**
 * @struct RTT_Challenge_
 *
 * This structure contains information regarding RTT_Challenge message.
 */
typedef struct RTT_Challenge_ {
	u8 msg_id;
	u8 L_lsb[16];
} RTT_CHALLENGE;

/**
 * @struct LC_Send_L_prime_pc
 *
 * This structure contains information regarding LC_Send_L_prime_pc message
 */
typedef struct LC_Send_L_prime_pc {
	u8 msg_id;
	u8 L_msb[16];
} LC_SEND_L_PRIME_PC;

/**
 * @struct LC_Send_L_prime_
 *
 * This structure contains information regarding LC_Send_L_prime message.
 */
typedef struct LC_Send_L_prime_ {
	u8 msg_id;
	u8 L[32];
} LC_SEND_L_PRIME;

/**
 * @struct SKE_Send_Eks_
 *
 * This structure contains information regarding SKE_Send_Eks message.
 */
typedef struct SKE_Send_Eks_ {
	u8 msg_id;
	u8 Eks[16];
	u8 riv[8];
} SKE_SEND_EKS;

/**
 * @struct SKE_Send_Eks_Ver23_
 *
 * This structure contains information regarding SKE_Send_Eks message for HDCP 2.3.
 */
typedef struct SKE_Send_Eks_Ver23_ {
	u8 msg_id;
	u8 Eks[16];
	u8 riv[8];
	u8 H[32];
} SKE_SEND_EKS_VER23;

//4.3.11 Table  4.14 RepeaterAuth_Send_ReceiverId_List(Transmitter to Receiver)
/**
 * @struct Device_Receiver_ID_
 *
 * This structure contains information regarding Device Receiver Id.
 */
typedef struct Device_Receiver_ID_ {
	u8 RECEIVER_IDj[5];
} DEVICE_RECEIVER_ID;

typedef struct RepeaterAuth_Send_ReceiverId_List21_ {
	u8 msg_id;
	u8 MAX_DEVS_EXCEEDED;
	u8 MAX_CASCADE_EXCEEDED;
	u8 DEVICE_COUNT;
	u8 DEPTH;
	u8 HDCP2_LEGACY_DEVICE_DOWNSTREAM;
	u8 HDCP1_DEVICE_DOWNSTREAM;
	u8 seq_num_V[3];
	u8 V_PRIME[16];
	DEVICE_RECEIVER_ID RECEIVER_IDs[31];
} REPEATERAUTH_SEND_RECEIVER_ID_LIST21;

//4//4.3.11 Table  4.13 RepeaterAuth_Send_ReceiverId_List(Transmitter to Receiver)
/**
 * @struct RepeaterAuth_Send_ReceiverId_List20_
 *
 * This structure contains information regarding RepeaterAuth_Send_ReceiverId_List message.
 */
typedef struct RepeaterAuth_Send_ReceiverId_List20_ {
	u8 msg_id;
	u8 MAX_DEVS_EXCEEDED;
	u8 MAX_CASCADE_EXCEEDED;
	u8 DEVICE_COUNT;
	u8 DEPTH;
	u8 V_PRIME[32];
	DEVICE_RECEIVER_ID RECEIVER_IDs[31];
}REPEATERAUTH_SEND_RECEIVER_ID_LIST20;

//4.3.14  RepeaterAuth_Send_Ack(Transmitter to Receiver)
/**
 * @struct RepeaterAuth_Send_Ack_
 *
 * This structure contains information regarding RepeaterAuth_Send_Ack message.
 */
typedef struct RepeaterAuth_Send_Ack_ {
	u8 msg_id;
	u8 V[16];
}REPEATERAUTH_SEND_ACK;

//4.3.17  Receiver_AuthStatus(Transmitter to Receiver)
/**
 * @struct Receiver_AuthStatus_
 *
 * This structure contains information regarding Receiver_AuthStatus message.
 */
typedef struct Receiver_AuthStatus_ {
	u8 msg_id;
	u8 LENGTH[2];
	u8 REAUTH_Req;
}RECEIVER_AUTHSTATUS;

/**
 * @struct Downstream_Params_
 *
 * This structure contains information regarding Downstream_Params message.
 */
typedef struct Downstream_Params_ {
	u8 streamCtrj[4];
	/*
	 * [15:13] =0
	 * [12:0] = PID
	 */
	u8 ContentStreamIDj[2];
	u8 Type;
} Downstream_Params;

//4.3.15  RepeaterAuth_Stream_Manage(Transmitter to Receiver)
/**
 * @struct RepeaterAuth_Stream_Manage_
 *
 * This structure contains information regarding RepeaterAuth_Stream_Manage message.
 */
typedef struct RepeaterAuth_Stream_Manage_ {
	u8 msg_id;
	u8 seq_num_M[3];
	u8 k[2];
	Downstream_Params max_k_info[16];
} REPEATERAUTH_STREAM_MANAGE;

/**
 * @struct RepeaterAuth_Stream_Info_
 *
 * This structure contains information regarding RepeaterAuth_Stream_Info message.
 */
typedef struct RepeaterAuth_Stream_Info_ {
	u8 msg_id;
	u8 no_of_streams[2];
	Downstream_Params multi_streaminfo[16];
} REPEATERAUTH_STREAM_INFO;

//4.3.16  RepeaterAuth_Stream_Ready(Receiver to Transmitter)
/**
 * @struct RepeaterAuth_Stream_Ready_
 *
 * This structure contains information regarding RepeaterAuth_Stream_Ready message.
 */
typedef struct RepeaterAuth_Stream_Ready_ {
	u8 msg_id;
	u8 M_PRIME[32];
} REPEATERAUTH_STREAM_READY;

/* Structure to hold the pointers to multiple buffer space*/
/**
 * @def TZ_OUT_BUF_MAX
 *
 * This macro is assigned value of 10 to indicate maximum size of trustzone output buffer.
 */
#ifdef CONFIG_HDCP_64BIT
#define TZ_OUT_BUF_MAX	512
#else
#define TZ_OUT_BUF_MAX	10
#endif /* CONFIG_HDCP_64BIT */

/**
 * @struct tz_buf_array_seg
 *
 * This structure contains information regarding the array segment of tz buffer.
 */
#ifdef CONFIG_HDCP_64BIT
struct tz_buf_array_seg {
	u64 _address;
	u32 _size;
}__attribute__ ((packed));
#else
struct tz_buf_array_seg {
	u32 _address;
	u32 _size;
}__attribute__ ((packed));
#endif /* CONFIG_HDCP_64BIT */

/**
 * @struct tz_buf_array_s
 *
 * This structure contains information regarding the array segment of tz buffer.
 */
/* Structure to hold the pointers to multiple buffer space*/
typedef struct tz_buf_array_s {
	struct tz_buf_array_seg _tz_buf_seg[TZ_OUT_BUF_MAX];
	u32 _seg_num;
}__attribute__ ((packed)) tz_buf_array_s_t;

#pragma pack(push, 1)

/**
 * @struct Cipher_Data_Info_TX
 *
 * This structure contains information regarding Cipher_Data_Info_TX.
 */
typedef struct Cipher_Data_Info_TX {
	u32 dummy;
#ifndef CONFIG_HDCP_64BIT
	tz_buf_array_s_t input_data;  // USE MM_HEAP which is scattered memory
	tz_buf_array_s_t output_data; // USE QSECOM_HEAP which is a linear memory
#endif /* !CONFIG_HDCP_64BIT */
	u32 str_ctr;
	u64 inp_ctr;
	u32 length;
	u8 *input;
	u8 *output;
	u8 dummy_arr[60];
#ifdef CONFIG_HDCP_64BIT
	tz_buf_array_s_t output_data; // USE QSECOM_HEAP which is a linear memory
	tz_buf_array_s_t input_data;  // USE MM_HEAP which is scattered memory
#endif /* CONFIG_HDCP_64BIT */
} CIP_DATA_INFO_TX;

/**
 * @struct CIP_DATA_INFO_RX
 *
 * This structure contains information regarding CIP_DATA_INFO_RX.
 */
typedef struct Cipher_Data_Info_RX {
	u8 msg_id;
	u32 str_ctr;
	u64 inp_ctr;
	u32 length;
	u32 dec_type;
	u32 codec_type;
	u8 *output;
	u8 *input;
} CIP_DATA_INFO_RX;

/**
 * @struct Cipher_Data_Info_ION_RX
 *
 * This structure contains information regarding Cipher_Data_Info_ION_RX.
 */
typedef struct Cipher_Data_Info_ION_RX {
	u8 msg_id;
	u32 str_ctr;
	u64 inp_ctr;
	u32 length;
	u32 dec_type;
	u32 codec_type;
	u8 *output;
	u8 *input;
	tz_buf_array_s_t input_data;
	tz_buf_array_s_t output_data;
} CIP_DATA_INFO_ION_RX;

#pragma pack(pop)

/**
 * @def MemSeg(memArray, i)
 *
 * This macro is trying to access the index of the memory array.
 */
#define MemSeg(memArray, i)	((memArray->_tz_buf_seg)+i)

/**
 * @def MemSegNum(memArray)
 *
 * This macro is trying to access the segment number of the memory array.
 */
#define MemSegNum(memArray)	(memArray->_seg_num)

/**
 * @def SegAddress(memSeg)
 *
 * This macro is trying to access the segment address of the memory segment.
 */
#define SegAddress(memSeg)	(memSeg->_address)

/**
 * @def SegSize(memSeg)
 *
 * This macro is trying to get the size of the memory segment.
 */
#define SegSize(memSeg)	(memSeg->_size)

/**
 * @def DEC_TYPE_NORMAL
 *
 * This macro is assigned value of 0x00 to indicate decimal type normal value.
 */
#define DEC_TYPE_NORMAL	0x00

/**
 * @def DEC_TYPE_CHECK_KEY_FRAME
 *
 * This macro is assigned value of 0x01 to check Key frame type.
 */
#define DEC_TYPE_CHECK_KEY_FRAME	0x01

/**
 * @def DEC_TYPE_AUDIO
 *
 * This macro is assigned value of 0x02 to check input type as audio.
 */
#define DEC_TYPE_AUDIO	0x02

/**
 * @def DEC_TYPE_VIDEO
 *
 * This macro is assigned value of 0x03 to check input type as video.
 */
#define DEC_TYPE_VIDEO	0x03

/**
 * @def DEC_MAX_HEADER_SIZE
 *
 * This macro is assigned value of 960 to indicate maximum header size.
 */
#define DEC_MAX_HEADER_SIZE	960

/**
 * @def DEC_MIN_HEADER_SIZE
 *
 * This macro is assigned value of 5 to indicate minimum header size.
 */
#define DEC_MIN_HEADER_SIZE	5

/**
 * @def DEC_MAX_AUDIO_VIDEO
 *
 * This macro is assigned value of 96 to indicate maximum audio-video streams allowed.
 */
#define DEC_MAX_AUDIO_VIDEO	96

#ifdef CONFIG_HDCP_64BIT
typedef enum {
	E_SECMATH_SUCCESS = 0,	///< Result OK
	E_SECMATH_FAILURE,	///< Generic Error */
	E_SECMATH_NOP,	///< Not a failure but no operation was performed */
	E_SECMATH_FAIL_TESTVECTOR,	///< Algorithm failed test vectors */
	E_SECMATH_BUFFER_OVERFLOW,	///< Not enough space for output */
	E_SECMATH_MEM,	///< Out of memory */
	E_SECMATH_INVALID_ARG,	///< Generic invalid argument */
	E_SECMATH_INVALID_PRIME_SIZE,	///< Invalid size of prime requested */
	E_SECMATH_NOT_SUPPORTED	///< Operation not supported
} SECMATH_ERRNO_ET;

typedef enum {
	/* Result OK */
	CE_SUCCESS = E_SECMATH_SUCCESS,
	/* Generic Error */
	CE_ERROR_FAILURE = E_SECMATH_FAILURE,
	/* Not a failure but no operation was performed */
	CE_ERROR_NOP = E_SECMATH_NOP,
	/* Algorithm failed test vectors */
	CE_ERROR_FAIL_TESTVECTOR = E_SECMATH_FAIL_TESTVECTOR,
	/* Not enough space for output */
	CE_ERROR_BUFFER_OVERFLOW = E_SECMATH_BUFFER_OVERFLOW,
	/* Out of memory */
	CE_ERROR_NO_MEMORY = E_SECMATH_MEM,
	/* Generic invalid argument */
	CE_ERROR_INVALID_ARG = E_SECMATH_INVALID_ARG,
	/* Invalid size of prime requested */
	CE_ERROR_INVALID_SIZE = E_SECMATH_INVALID_PRIME_SIZE,
	/* Operation not supported */
	CE_ERROR_NOT_SUPPORTED = E_SECMATH_NOT_SUPPORTED,
	/* invalid signature  */
	CE_ERROR_INVALID_SIGNATURE = 0x1000,
	/* decrypt error  */
	CE_ERROR_DECRYPT_ERROR = 0x1002,
	/* invalid packet  */
	CE_ERROR_INVALID_PACKET = 0x1003,
	/* message too long  */
	CE_ERROR_MESSAGE_TOO_LONG = 0x1004,
} CeErrorType;
#else
/* Result OK */
#define CE_SUCCESS	0
#endif /* CONFIG_HDCP_64BIT */

#define HDCP2_AES_KEY_SIZE 16

typedef struct cipher_key_ {
	u8 label[HDCP2_AES_KEY_SIZE];
	u8 context[HDCP2_AES_KEY_SIZE];
	u8 key[HDCP2_AES_KEY_SIZE];
} CIPHER_KEY;

#ifdef __cplusplus
}
#endif

#endif /* !_HDCP2_COMMON_H_ */
