/**
 * 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.
 *
 */

// v2.00   2013.01.16    Initial version v2.00 (Exynos5xxx, APQ8064)
// v2.01   2013.01.21    Append MFC Firware Load code for exynos5xxx (to be removed)
// v2.02   2013.01.22    Adjust APIs
// v2.03   2013.01.23    Fix SPC connection issue (LC init timeout) <- remove log
// v2.04   2013.01.24    Fix connection error (Notify wrong value)
// v2.05   2013.01.25    Fix PLM-130123-3444 (libhdcp2.so crash during re-calling HDCP2_Init)
// v2.06   2013.01.25    Add ion-addr conversion table
// v2.07   2013.01.28    Remove ion-addr conversion table
// v2.08   2013.02.15    APQ8064 sets bandwidth as high to use H/W crypto.
// v2.09   2013.02.18    Timeout for HDCP_SIZE_RECEIVERAUTH_STATUS is increased as 900ms
// v2.10   2013.02.20    Remove tlApiSecSssInit(), tlApiSecSssExit() in TZ_Cipher_AES_CTR_Decrypt() and TZ_Cipher_AES_CTR_Encrypt
// v2.11   2013.02.21    fix checking argument before starting server_repeater()
// v2.12   2013.02.22    Support dynamic stream management and add some notifications to WFD
// v2.13   2013.02.22    Add checking if hdcp is null
// v2.14   2013.02.26    8064 calls set hdcp.
// v2.15   2013.02.22    hdcp->opened is moved. (problem happend with device doesn't have key)
// v2.16   2013.02.28	 Remove MFC Firmware Load code and Add checking iframe function
// v2.17   2013.03.04	 Add MFC Firmware Load code (to be removed)
// v2.18   2013.03.08	 Set MIF Clock Frequency (request from S.LSI, affect 5410 only)
// v2.19   2013.03.12	 Fix bind failure problem
// v2.20   2013.03.12    [JA] HDCP2_Encrypt() / output buffer : ion -> va
// v2.21   2013.03.13	 Fix HDCP2_DownstreamPropagation timeout problem.
// v2.22   2013.03.15	 Change position loading MFC FW(to be removed)
// v2.23   2013.03.18	 Remove MFC firmware load code
// v2.24   2013.03.18    Intel key installation is supported
// v2.25   2013.03.20    Fix bind failure problem(2)
// v2.26   2013.03.22    set wlan.hdcp.ver if transmitter works.
// v2.27   2013.04.01    [CLT] edit to check hdcp key
// v2.28   2013.04.04    [Common] Disable Precomputed LC for Tx (dongle cannot handle precomputed LC properly)
// v2.29   2013.04.04    Add checking null pointer as parameter
// v2.30   2013.04.04    Add releasing thread feature
// v2.31   2013.04.06    Bug fix about terminating thread (remove 2.30 feature)
// v2.32   2013.04.18    Fix never returning HDCP2_Start_Repeater() when source does not have a HDCP key
// v2.33   2013.04.19    Support HDCP v2.2. This option has included in mobicore.sh
// v2.34   2013.04.24    Add set bandwidth in TZ_Open and TZ_Close functions. Remove HW_Init and HW_Close functions.
// v2.35   2013.04.24    [QC] Use ion.h, msm_ion.h for MSM8930&MSM8974
// v2.36   2013.04.29    Add verifying DLP-LLC's signature on receiver's cert
// v2.37   2013.05.02    Support non-block mode connect()
// v2.38   2013.05.13    Change connection duration for wfd from 10 msecs to 20 msecs
// v2.39   2013.05.22    MSM8974 uses scattered memory
// v2.40   2013.05.24    [swd] Add verifying DLP-LLC's signature on receiver's cert for test vector
// v2.41   2013.05.31    [swd] Remove __TZ_Check_Frame_Condition which is added for discarding ADU and Filter data frame
// v2.42   2013.06.03    exynos3470 Integration with HDCP code
// v2.43   2013.06.04    [nwd] Check h2k directory presence
// v2.44   2013.06.05    [Chaabi] Add content key deletion function, set do not store pairing info
// v2.45   2013.06.06    [QC] 64bytes aligned communication
// v2.46   2013.06.09    [QC] QC uses No store Km since it seems that using sfs has an issue.
// v2.47   2013.06.10    [QC] Use stored Km. If QSEECom_send_cmd fails, return -51 err so that it can be disconnected soon.
// v2.48   2013.06.14    [Chaabi] modify to display extapp hdcp version when h/w init.
// v2.49   2013.06.26    [nwd] Receiver enabled for msm8974.
// v2.50   2013.07.05    [nwd] Add a function and usages to check receive message ID.
// v2.51   2013.07.09    [Chaabi] add os and library verification function
// v2.52   2013.08.02    [nwd] add to call fflush function to sync with disk when WrapKeyData
// v2.53   2013.08.02    [Chaabi] Change decrypt function for Rx
// v2.54   2013.08.09    [NWD] Change timeout same as HDCP specification
// v2.55   2013.08.23    [Chaabi] modify ENC_DATA function, LoadKey function
// v2.56   2013.08.23    [NWD] Display log clear and decrease connection time
// v2.57   2013.08.26    [Chaabi] modify IsKeyFrame check function
// v2.58   2013.08.29    [nwd] modify flush code and socket timeout when retry AKE
// v2.59   2013.09.23    [nwd] Modify the log about Pairing Inforamation seemed an error when it connects a device at first.
// v2.60   2013.10.04    [Chaabi] modify decrypt and encrypt function for Rx
// v2.61   2013.10.11    [nwd] add HDCP2_Encrypt_PP function for google stack miracast
// v2.62   2013.11.06    [QC] change secure app name of Tizen
// v2.63   2013.11.20    [nwd] modify reqeater-related codes to support multi repeater.
// v2.64   2013.11.21    [nwd] Add libstagefright files; Include Google stack related changes for Qualcomm
// v2.65   2013.11.22    [swd] modify reqeater-related codes to support multi reapeater of mobicore
// v2.66   2013.11.25    [nwd] modify encrypt_drm function for S.LSI google stack miracast
// v2.67   2013.11.27    [nwd] modify HDCP2_Encrypt_Drm to include missing packets
// v2.68   2013.12.03    [nwd] modify code to enable screen mirroring for msm8974_KitKat
// v2.69   2013.12.04    [nwd] QSEE_COMMAND_ION modification for APQ8064
// v2.70   2013.12.04    [nwd] modify encrypt stack for changed S.LSI input data type
// v2.71   2013.12.04    [nwd] merge codes for encrypt and encryptNative APIs for Qualcomm
// v2.72   2013.12.10    [nwd] add support for HDCP v2.0 along with HDCP v2.1 and v2.2
// v2.73   2013.12.11    [swd] Fix checking in which secure boot is enabled or not
// v2.74   2013.12.13    [nwd] disable unmap output buffer in Encrypt_Drm of Mobicore 5xxx
// v2.75   2013.12.13    [nwd] Modify the file name to store pairing information for Exynos
// v2.76   2013.12.19    [nwd] include HDCP2 version switching to v2.1
// v2.77   2013.12.26    [libsf] move inputCtr value from encrypt function to Class protected value
// v2.78   2013.12.30    [nwd] modify broken screen during screen mirroring
// v2.79   2014.01.06    [nwd] Remove create directory to store pairing information for Qualcomm
//                             Fix the directory name to store pairing information for Exynos
// v2.80   2014.01.07    [nwd-swd] Fix WatchOn for KitKat (msm8974)
// v2.81   2014.01.08    [nwd] Fix HDCP2 version switching for compatibility
// v2.82   2014.01.10    [nwd] handle connection thread exit in libstagefright_hdcp
// v2.83   2014.01.13    [nwd] MC20 for Exynos4x12 integrated from 1714 to 1716 perforce port
// v2.84   2014.01.24    [nwd] modify wfd and smartview to send RTT_Ready only if hdcp version is 2.1 over
// v2.85   2014.02.06    [nwd] update secdrv and disable HDCP2_GetContentStreamType API for 5422 and 5430
// v2.86   2014.02.17    [nwd & swd] Support handling (TRANSMITTER or RECEIVER)_LOCALITY_PRECOMPUTE_SUPPORT during Locality Check
// v2.87   2014.02.26    [swd] Disable (TRANSMITTER or RECEIVER)_LOCALITY_PRECOMPUTE_SUPPORT due to incompatability with TVs
// v2.88   2014.03.03    [nwd] Ignore mcOpenDevice() error
// v2.89   2014.03.03    [swd] HDCP v2.2 is enabled. TX/RX are able to connect for both Precomputaion and No-Precomputation.
// v2.90   2014.03.11    [nwd-swd] Modifications done to resolve prevent issues.
// v2.91   2014.03.26    [nwd] Modification done in wfd.cpp to resolve network issue
// v2.92   2014.04.04    [nwd] Fix the wrong PID value(endian-ness issue)
// v2.93   2014.04.11    [nwd] modify mobicore build environment and add log for debugging
// v2.94   2014.04.11    [nwd & swd](1) delete all of HDCP2_VERSION22_TEST feature,
//                                  (2)version setup is done in swd the same time when done in nwd
//                                  (3) protocol descriptor is used from receiver cert, explicit setting is removed
//                                  (4) HMAC calculated according to protocol descriptor
// v2.95   2014.04.22    [nwd] added HDCP2_HW_Close function call in HDCP2_TZ_Close for hdcp2_mobicore_exynos4x12.cpp
// v2.96   2014.04.24    [nwd & swd] version setup is done in swd the same time when done in nwd for qualcomm
// v2.97   2014.05.08    [nwd] added retry code for HDCP2.2 if it fails in reading AKE certificate and switch to HDCP2.1 if tries exceeds 5 times.
// v2.98   2014.05.16    [nwd & swd] code modification as per the Errata document published for HDCP2.2
// v2.99   2014.05.30    [nwd & swd] fix HDCP 2.2 spec (section 2.3, second paragraph)compliance issue related to Locality Check
// v3.00   2014.06.03    [nwd] fix prevent issues.
// v3.01   2014.07.02    [swd] add driver folder for exynos5433. config changes for build.
// v3.02   2014.07.02    [swd] add USE_CPP feature
// v3.03   2014.07.04    [nwd-swd] Added HDCP2_CopyToSecureMem API to copy from input to output without decryption
// v3.04   2014.07.14    [nwd] Corrected pre-compute disable check which was keeping on toggling pre-compute in case of an error.
// v3.05   2014.07.16    [nwd-swd] Corrected the structure HDCP2_RECEIVER_CERTIFICATE, split the reserved bits as per the concept of bit field.
// v3.06   2014.07.17    [nwd] added build options in build_qc.sh for 8916 and 8084.
// v3.07   2014.07.30    [nwd-swd] (1) retry with disable precompute if Rx precompute is disabled. (2) set Content stream bit only if precompute enable.
// v3.08   2014.08.01    [swd] Made qsee receiver code working. Removed Vienna repeater code.
// v3.09   2014.09.09    [nwd] Detailed error logs added to make debugging easier
// v3.10   2014.10.07    [nwd] Removed re-auth with disable precompute (Continue without re-auth).
// v3.11   2014.10.12    [nwd] added checking log for protocol descriptor.
// v3.12   2014.10.13    [nwd-swd] modify changing version conditional
// v3.13   2014.10.15    [nwd] added USE_L macro for libstagefright
// v3.14   2014.10.17    [nwd] merged Blowfish nwd code
// v3.15   2014.10.17    [nwd] used latest HDCPAPI.h for L OS
// v3.16   2014.11.06    [nwd-swd] Fix issues in Rx code
//                                 [nwd] - Set hdcp version to swd after swd context is reset (i.e after AKE Init_R TZ Call)
//                                 [swd] - Always reset context during AKE_Init_R
// v3.17   2014.11.10    [nwd] Disable Pre-compute because of issue with 2013 TV
// v3.18   2014.11.20    [nwd-swd] apply HW_CRYPTO for Blowfish TX (swd changes in bf_hdcp2_swd only)
// v3.19   2014.11.21    [nwd] fix crash in memcpy in HDCP2_Encrypt_VV - allocate MAX_INPUT_LENTH instead of MAX_ENCRYPT_BUFFER during crypt_mem_init
// v3.20   2014.11.26    [nwd] change return value to HDCP_CAPS_ENCRYPT_NATIVE on getCaps()
// v3.21   2014.12.19    [nwd-swd] modify H/W encryption function on Exynos7420
// v3.22   2014.12.26    [swd] update mobicore 7420 build enviornment
// v3.23   2014.12.30    [nwd] move hdcp key location from /efs to /efs/cpk
// v3.24   2015.03.11    [nwd] modified to use SW crypto on blowfish
// v3.25   2015.03.24    [nwd-swd] minor code optimization done in nwd and swd code related to Blowfish
// v3.26   2015.03.27    [nwd] Increase the re-try count to prevent from socket connection failure with SOT21(Sony experia) tablet. (Requested by KDDI) 
// v3.27   2015.03.27    [nwd-swd] Increase in buffersize used in HDCP2_CopyToSecmem to 0x8000 to enhance the performance
// v3.28   2015.04.13    [nwd-swd] Port HDCP code for Marvell TZ. swd code is modified in bf_hdcp2_swd
// v3.29   2015.05.06    [swd] Blowfish code is modified to use GP APIs instead of memcpy, memset and memcmp
// v3.30   2015.05.14    [swd] Blowfish code is modified to fix upload issue in SW crypto on Qualcomm device. Also fixed printf log
// v3.31   2015.05.18    [nwd-swd] Fixed Blowfish Receiver code
// v3.32   2015.05.26    [nwd-swd] Blowfish Receiver code is updated to use HW Crypto for decryption and ION memory for Input Buffer
// v3.33   2015.05.27    [nwd] HDCP on Marvell Prevent Fix
// v3.34   2015.06.03    [nwd] Improve Blowfish Current Consumption at QC
// v3.35   2015.06.04    [nwd-swd] Blowfish Transmitter code is updated to use ION memory for Output Buffer.
// v3.36   2015.06.08    [nwd-swd] Added HDCP2_CopyToSecureMem_ION API to copy from input to output without decryption for qualcomm.
// v3.37   2015.06.10    [nwd] In Blowfish code, Removed hardcoded MEM_MAX_PAGES and updated to allocate them dynamically. Also removed few redundant codes.
// v3.38   2015.06.11    [swd] Added drivers for TAB-S2 (exynos5433_tbase302) and modified mobicore.sh to include those.
// v3.39   2015.06.16    [swd] Modified logic of TZ_SPSPPS_COPY for TbaseAPI_Level5
// v3.40   2015.06.16    [swd] Fixed signing type to samsung_drv from dev_drv for Blowfish
// v3.41   2015.06.18    [nwd-swd] (Temporary Modification) Convert from hdcp key to the key encrypted device key for Blowfish
// v3.42   2015.06.23    [nwd-swd] Modified flag options for memory allocation/mapping for Blowfish performance improvement
// v3.43   2015.06.24    [nwd-swd] Reduced shared memory with swd and Added checking OEM flag for integrity check (for blowfish)
// v3.44   2015.06.29    [nwd] Fix the check for Decrypt Audio in hdcp2_mobicore.cpp
// v3.45   2015.07.01    [nwd] Reduced the size of ION buffer for encryption/decryption (for T-base)
// v3.46   2015.07.08    [swd] (for T-base) TZ_SPSPPS_COPY is modified to use tbase_level5 APIs(tlApiMalloc/tlApiFree) only for exynos 5430, 4333, 7420, 3475, exynos5430_tbase302 & exynos5433_tbase302
//                       [nwd]  Set MAX_SPS_BUFFER to 64KB as tlapi(tlApiVirt2PhysMemcpy) supports max 64KB
//                       [swd] Also added drivers for exynos3475
// v3.47   2015.07.08    [nwd-swd] [RX] Fix version in AKE_Receiver_Info for HDCP Spec 2.2
// v3.48   2015.07.28    [nwd-swd] Fixed/Updated Blowfish nwd & swd Code for Exynos Chipset
// v3.49   2015.07.28    [swd] Blowfish swd changes for new sdk blowfish-sdk-1.0-update1
// v3.50   2015.10.02    [swd] Added drivers for exynos8890 and modified mobicore.sh
// v3.51   2015.10.06    [swd] Only qc_hdcp2_swd is changed to make msm8996 porting change (related to qsee_is_s_tag_area)
// v3.52   2015.10.19    [nwd-swd] HDCP2_SpsPpsToSecmem is implemented at Blowfish
// v3.53   2015.10.19    [swd] Added the routine to copy return value of TZ for msm8996
// v3.54   2015.10.19    [nwd] removed unsupported ioctl for exynos8890 trustlet_MC310
// v3.55   2015.11.05    [swd] Updated HDCP TA for msm8996 as QC patch(Pre-CS 0.1.550.3a PATCH) was applied
// v3.56   2015.11.09    [nwd-swd] Modified codes for SPS buffer to build APQ8064
// v3.57   2015.11.13    [nwd-swd] Applied HDCP 64bit-TA to MSM8996
// v3.58   2015.11.17    [nwd-swd] Modified data struct for 64bit TA on MSM8996
// v3.59   2015.11.25    [nwd-swd] Enabled Receiver for MSM8996
// v3.60   2015.11.27    [nwd] Increase the re-try count to prevent from socket connection failure with SOT21(Sony experia) tablet. (Requested by KDDI)
// v3.61   2016.01.18    [swd] Added check routine if output buffer is secure in receiver operation. (for MSM8996)
// v3.62   2016.02.19    [nwd] Modified the routine checking whether version of T-base is MC310.
// v3.63   2016.03.14    [swd] Add a new routine to check if CSB is enabled in all QC project.
// v3.64   2016.07.12    [nwd] Merging LSI code (hdcp2_exynos.cpp, hdcp2_mobicore.cpp)
// v3.65   2017.01.19    [swd] Update "secSSS_t struct" for TabS2(Use the SDK - 5433-tabs2-topic)
// v3.66   2017.02.20    [nwd-swd] For Qualcomm chipset over MSM8998, don't use SFS. Add feature "USE_QSEE_WRAP_WITH_SFS" for old chipset
//                       [swd] Divide the file which includes wrap APIs into two parts(Loadkey/Decodekey) for Qualcomm
// v3.67   2017.04.18    [nwd] Get the property about key storage during HDCP init
// v3.68   2017.05.18    [swd] (for T-base) Use tbase APIs(tlApiSignatureVerify) for HDCP negotication(verify RSA signature - dcp_llc_sign) instead of PolarSSL
// v3.69   2017.05.18    [swd] (for T-base) Boundary check is added to keep buffer overflow when stream management(TZ_RepeaterAuth_Stream_Manage_T, TZ_RepeaterAuth_Stream_Ready_T)
// v3.70   2017.05.22    [nwd-swd] Added logic for split encryption(for Tbase only)and increase encrypt buffer size for direct stream.
// v3.71   2017.07.17    [swd] (MTK-Teegris) Modified logic getting physical address of output buffer provided by decoder in TV2Mobile Case.
// v3.72   2017.08.17    [nwd-swd] (Exynos-Kinibi) Apply 64bit physical address system
// v3.73   2017.08.17    [nwd-swd] (Exynos-Kinibi) Support WFD HW IP for exynos9810(Lhotse)
// v3.74   2017.12.06    [swd] Enable Stack protection and prevent buffer overflow in "TZ_RepeaterAuth_Send_ReceiverId_List(kinibi)"
// v3.75   2018.01.16    [swd] (Exynos-Kinibi) Apply patch of LSI(Add logic of sending HDCP version to DRM solution)
// v3.76   2018.05.18    [nwd-swd] Apply HDCP v2.3 (increase verification Rx - Add HMAC in SKE_Send_Eks)
// v3.77   2018.12.19    [nwd-swd] Latest Dev (CL 15005687)
// v3.78   2018.05.18    [nwd-swd] Revert HDCP v2.3 (increase verification Rx - Add HMAC in SKE_Send_Eks)
// v3.79   2019.07.16    [nwd-swd] Apply HDCP v2.3 (increase verification Rx - Add HMAC in SKE_Send_Eks)
// v3.80   2019.11.07    [nwd] Apply re-connection for unknown pipe error with EINPROGRESS with 2013 TV
#define HDCP2_INFO_1    " =========================================="
#define HDCP2_INFO_1    " =========================================="
#define HDCP2_INFO_2    " |              HDCP2 v3.80               |"
#define HDCP2_INFO_3    " =========================================="
