Initial commit: Linux kernel 4.19 for Unplugged OS

This commit is contained in:
ziv committed 2025-10-06 13:52:42 +00:00
commit d30235b04c
80519 files changed
+35800681

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
#
#HDCP crypto ca
#
ifeq ($(CONFIG_TRUSTONIC_TEE_SUPPORT),y)
include $(srctree)/drivers/misc/mediatek/gud/Makefile.include
endif
ifeq ($(CONFIG_MICROTRUST_TEE_SUPPORT),y)
include $(srctree)/drivers/misc/mediatek/teei/Makefile.include
endif
obj-y += tlcDpHdcp.o
#ccflags-y += -DHDCP_SETKEY_FROM_KERNEL
+183
View File
@@ -0,0 +1,183 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __TCI_H__
#define __TCI_H__
typedef uint32_t tciCommandId_t;
typedef uint32_t tciResponseId_t;
typedef uint32_t tciReturnCode_t;
typedef uint32_t TEE_VA_TYPE;
#define RET_COMPARE_PASS 0
#define RET_COMPARE_FAIL 1
#define RET_NEW_DEVICE 2
#define RET_STORED_DEVICE 3
#define AN_LEN 8
#define AKSV_LEN 5
#define BKSV_LEN 5
#define CERT_LEN 522
#define EKM_LEN 16
#define M_LEN 16
#define ENC_KM_LEN 128
#define RXX_LEN 8
#define CAPS_LEN 3
#define RN_LEN 8
#define RIV_LEN 8
#define TYPE_HDCP_PARAM_AN 10
#define TYPE_HDCP_PARAM_RST_1 11
#define TYPE_HDCP_PARAM_RST_2 12
#define TYPE_HDCP_ENABLE_ENCRYPT 13
#define TYPE_HDCP_DISABLE_ENCRYPT 14
//for test
#define TYPE_HDCP13_KEY 20
#define TYPE_HDCP22_KEY 21
struct cryptokeys_t {
uint8_t type;
uint32_t len;
TEE_VA_TYPE key;
};
/**
* TCI command header.
*/
struct tciCommandHeader_t {
tciCommandId_t commandId;
};
/**
* TCI response header.
*/
struct tciResponseHeader_t {
tciResponseId_t responseId;
tciReturnCode_t returnCode;
};
struct cmdHDCPInitForVerion_t {
uint32_t version;
bool needLoadKey;
};
struct cmdHDCPWriteVal_t {
uint8_t type;
uint8_t len;
TEE_VA_TYPE val;
};
struct cmdHDCPCalculateLm_t {
uint8_t bksv[BKSV_LEN];
};
struct cmdHDCPGetAksv_t {
uint8_t aksv[AKSV_LEN];
};
struct cmdHDCPSha1_t {
uint32_t message_len;
TEE_VA_TYPE message_addr;
};
struct cmdHDCPAKECertificate_t {
uint8_t certification[CERT_LEN];
bool bStored;
uint8_t m[M_LEN];
uint8_t ekm[EKM_LEN];
};
struct cmdHDCPAKEParing_t {
uint8_t ekm[EKM_LEN];
};
struct cmdHDCPEncKm_t {
uint8_t encKm[ENC_KM_LEN];
};
struct cmdHDCPAKEHPrime_t {
uint8_t rtx[RXX_LEN];
uint8_t rrx[RXX_LEN];
uint8_t rxCaps[CAPS_LEN];
uint8_t txCaps[CAPS_LEN];
uint32_t rxH_len;
TEE_VA_TYPE rxH;
};
struct cmdHDCPLcLPrime_t {
uint8_t rn[RN_LEN];
uint32_t rxL_len;
TEE_VA_TYPE rxL;
};
struct cmdHDCPSKEEks_t {
uint8_t riv[RIV_LEN];
uint32_t eks_len;
TEE_VA_TYPE eks;
};
struct cmdHDCPCompare_t {
uint32_t rx_val_len;
TEE_VA_TYPE rx_val;
uint32_t param_len;
TEE_VA_TYPE param;
uint32_t out_len;
TEE_VA_TYPE out;
};
union tcicmdBody_t {
/* init with special HDCP version */
struct cmdHDCPInitForVerion_t cmdHDCPInitForVerion;
/* write uint32 data to hw */
struct cmdHDCPWriteVal_t cmdHDCPWriteVal;
/* get aksv */
struct cmdHDCPGetAksv_t cmdHDCPGetAksv;
/* calculate r0 */
struct cmdHDCPCalculateLm_t cmdHDCPCalculateLm;
/* generate signature for certificate*/
struct cmdHDCPAKECertificate_t cmdHDCPAKECertificate;
/* to store ekm*/
struct cmdHDCPAKEParing_t cmdHDCPAKEParing;
/* encrypt km for V2.2 */
struct cmdHDCPEncKm_t cmdHDCPEncKm;
/* compute H prime */
struct cmdHDCPAKEHPrime_t cmdHDCPAKEHPrime;
/* compute L prime */
struct cmdHDCPLcLPrime_t cmdHDCPLcLPrime;
/* compute eks */
struct cmdHDCPSKEEks_t cmdHDCPSKEEks;
/* compare */
struct cmdHDCPCompare_t cmdHDCPCompare;
/* for test only */
struct cryptokeys_t cryptokeys;
} __attribute__ ((__packed__));
struct cmdHDCP_t {
/* request tci header */
struct tciCommandHeader_t commandHeader;
/* response tci header */
struct tciResponseHeader_t responseHeader;
uint32_t drHandle;
union tcicmdBody_t cmdBody;
};
/**
* TCI message data.
* It's union structure
*/
union tciMessage_t {
/* request tci include header and other parameters */
struct cmdHDCP_t cmdHDCP;
};
/**
* Overall TCI structure.
*/
struct tci_t {
union tciMessage_t message; /**< TCI message */
};
const static uint64_t TCI_LENGTH = sizeof(struct tci_t);
#endif //__TCI_H__
+36
View File
@@ -0,0 +1,36 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __DP_HDCP_CMD_H__
#define __DP_HDCP_CMD_H__
#define CMD_DEVICE_ADDED 1
#define CMD_DEVICE_REMOVE 2
#define CMD_WRITE_VAL 3
#define CMD_DEVICE_CLEAN 4
#define CMD_ENABLE_ENCRYPT 5
//V1.3
#define CMD_CALCULATE_LM 11
#define CMD_COMPARE_R0 12
#define CMD_COMPARE_V1 13
#define CMD_GET_AKSV 14
//V2.2
#define CMD_AKE_CERTIFICATE 20
#define CMD_ENC_KM 21
#define CMD_AKE_H_PRIME 22
#define CMD_AKE_PARING 23
#define CMD_LC_L_PRIME 24
#define CMD_COMPARE_L 25
#define CMD_SKE_CAL_EKS 26
#define CMD_COMPARE_V2 27
#define CMD_COMPARE_M 28
//need remove in furture
#define CMD_LOAD_KEY 50
#endif //__DP_HDCP_CMD_H__
+751
View File
@@ -0,0 +1,751 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/types.h>
#include <linux/string.h>
#include "tee_client_api.h"
#include "tlcDpHdcp.h"
#define LOG_TAG "DP_HDCP_CA"
#define AN_LEN 8
#define AKSV_LEN 5
#define DEFAULT_WRITE_VAL_LEN 1
#define DEFAULT_WRITE_VAL 0
//key id used in keyinstall
#define HDCP_1X_TX_ID 2
#define HDCP_2X_TX_ID 3
#define TZCMD_DRMKEY_LOAD_HDCPKEY 12
const struct TEEC_UUID uuid = {
0xabcd270e, 0xa5c4, 0x4c58,
{0xbc, 0xd3, 0x38, 0x4a, 0x2f, 0xa2, 0x53, 0x9e}
};
const struct TEEC_UUID KI_TA_UUID = {
0x08110000, 0x0000, 0x0000,
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
};
const static size_t MAX_SHARED_MEMORY_SIZE = 4 * 1024; // 4K
static struct TEEC_SharedMemory sSharedMemoryMain;
struct TEEC_Context sContext;
struct TEEC_Session sSession;
static bool g_init;
int tee_addDevice(uint32_t version)
{
uint32_t ret = TEEC_SUCCESS;
struct tci_t *tci;
struct TEEC_Operation op;
bool needLoadKey = false;
if (g_init)
tee_removeDevice();
#ifndef HDCP_SETKEY_FROM_KERNEL
//load key first
if (version > 0) {
ret = tee_loadHdcpKeyById(version);
if (ret != TEEC_SUCCESS) {
TLCERR("ret = 0x%x", ret);
return ret;
}
needLoadKey = true;
}
#endif
ret = TEEC_InitializeContext(NULL, &sContext);
if (ret != TEEC_SUCCESS) {
TLCERR("ret = 0x%x", ret);
return ret;
}
ret = TEEC_OpenSession(&sContext, &sSession, &uuid, TEEC_LOGIN_PUBLIC,
NULL, NULL, NULL);
if (ret != TEEC_SUCCESS) {
TLCERR("TEEC_OpenSession ret = 0x%x", ret);
TEEC_FinalizeContext(&sContext);
return ret;
}
// Try to register one 4M main share memory, if failed(means current
// tee don't support), register four 1M extra share memory instead.
// Only do this when first initialize.
sSharedMemoryMain.buffer = NULL;
sSharedMemoryMain.size = MAX_SHARED_MEMORY_SIZE;
sSharedMemoryMain.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
ret = TEEC_AllocateSharedMemory(&sContext, &sSharedMemoryMain);
if (ret == TEEC_SUCCESS) {
TLCINFO("Register 4k share memory successfully, (%p)",
sSharedMemoryMain.buffer);
} else {
TLCERR("Register 4k share memory failed(0x%x), (%p)",
ret, sSharedMemoryMain.buffer);
if (sSharedMemoryMain.buffer != NULL) {
TEEC_ReleaseSharedMemory(&sSharedMemoryMain);
sSharedMemoryMain.buffer = NULL;
}
}
// Copy parameter for add new device
tci = (struct tci_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_DEVICE_ADDED;
tci->message.cmdHDCP.cmdBody.cmdHDCPInitForVerion.version = version;
tci->message.cmdHDCP.cmdBody.cmdHDCPInitForVerion.needLoadKey =
needLoadKey;
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH;
ret = TEEC_InvokeCommand(&sSession, CMD_DEVICE_ADDED, &op, NULL);
if (ret != TEEC_SUCCESS) {
TLCERR("InvokeCommand ret = 0x%x", ret);
tee_removeDevice();
}
g_init = true;
return ret;
}
void tee_removeDevice(void)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameter for add new device
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
if (!g_init)
return;
g_init = false;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_DEVICE_REMOVE;
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH;
ret = TEEC_InvokeCommand(&sSession, CMD_DEVICE_REMOVE, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("ret = 0x%x", ret);
//Release all resources
if (sSharedMemoryMain.buffer != NULL) {
TEEC_ReleaseSharedMemory(&sSharedMemoryMain);
sSharedMemoryMain.buffer = NULL;
}
TEEC_CloseSession(&sSession);
TEEC_FinalizeContext(&sContext);
}
int tee_clearParing(void)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameter for add new device
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_DEVICE_CLEAN;
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH;
ret = TEEC_InvokeCommand(&sSession, CMD_DEVICE_CLEAN, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("ret = 0x%x", ret);
return ret;
}
int tee_hdcp1x_setTxAn(uint8_t *an_code)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
uint8_t an_len = 8;
// Copy parameter for add new device
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
uint8_t *share_buffer = (uint8_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_WRITE_VAL;
tci->message.cmdHDCP.cmdBody.cmdHDCPWriteVal.len = an_len;
tci->message.cmdHDCP.cmdBody.cmdHDCPWriteVal.type = TYPE_HDCP_PARAM_AN;
memcpy(share_buffer + TCI_LENGTH, an_code, an_len);
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH + an_len;
ret = TEEC_InvokeCommand(&sSession, CMD_WRITE_VAL, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("ret = 0x%x", ret);
return ret;
}
int tee_hdcp_enableEncrypt(bool bEnable, uint8_t version)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameter for add new device
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
uint8_t *share_buffer = (uint8_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_ENABLE_ENCRYPT;
if (bEnable)
tci->message.cmdHDCP.cmdBody.cmdHDCPWriteVal.type
= TYPE_HDCP_ENABLE_ENCRYPT;
else
tci->message.cmdHDCP.cmdBody.cmdHDCPWriteVal.type
= TYPE_HDCP_DISABLE_ENCRYPT;
//set HDCP version supportted by device
tci->message.cmdHDCP.cmdBody.cmdHDCPWriteVal.len = 1;
memset(share_buffer + TCI_LENGTH, version, 1);
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH + 1;
ret = TEEC_InvokeCommand(&sSession, CMD_ENABLE_ENCRYPT, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("ret = 0x%x", ret);
return ret;
}
int tee_hdcp1x_softRst(void)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameter for add new device
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
uint8_t *share_buffer = (uint8_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_WRITE_VAL;
tci->message.cmdHDCP.cmdBody.cmdHDCPWriteVal.type
= TYPE_HDCP_PARAM_RST_1;
//No need input. Set default value 0 for check
tci->message.cmdHDCP.cmdBody.cmdHDCPWriteVal.len =
DEFAULT_WRITE_VAL_LEN;
memset(share_buffer + TCI_LENGTH, DEFAULT_WRITE_VAL,
DEFAULT_WRITE_VAL_LEN);
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH + DEFAULT_WRITE_VAL_LEN;
ret = TEEC_InvokeCommand(&sSession, CMD_WRITE_VAL, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("ret = 0x%x", ret);
return ret;
}
int tee_hdcp2_softRst(void)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameter for add new device
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
uint8_t *share_buffer = (uint8_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_WRITE_VAL;
tci->message.cmdHDCP.cmdBody.cmdHDCPWriteVal.type
= TYPE_HDCP_PARAM_RST_2;
//No need input. Set default value 0 for check
tci->message.cmdHDCP.cmdBody.cmdHDCPWriteVal.len =
DEFAULT_WRITE_VAL_LEN;
memset(share_buffer + TCI_LENGTH, DEFAULT_WRITE_VAL,
DEFAULT_WRITE_VAL_LEN);
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH + DEFAULT_WRITE_VAL_LEN;
ret = TEEC_InvokeCommand(&sSession, CMD_WRITE_VAL, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("ret = 0x%x", ret);
return ret;
}
/** V1.X **/
int tee_getAksv(uint8_t *Aksv)
{
uint32_t ret = TEEC_SUCCESS;
struct tci_t *tci;
struct TEEC_Operation op;
// Copy parameters
tci = (struct tci_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_GET_AKSV;
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH;
ret = TEEC_InvokeCommand(&sSession, CMD_GET_AKSV, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("InvokeCommand ret = 0x%x", ret);
memcpy(Aksv, tci->message.cmdHDCP.cmdBody.cmdHDCPGetAksv.aksv,
AKSV_LEN);
return ret;
}
int tee_calculateLm(uint8_t *Bksv)
{
uint32_t ret = TEEC_SUCCESS;
struct tci_t *tci;
struct TEEC_Operation op;
// Copy parameters
tci = (struct tci_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_CALCULATE_LM;
memcpy(tci->message.cmdHDCP.cmdBody.cmdHDCPCalculateLm.bksv, Bksv,
BKSV_LEN);
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH;
ret = TEEC_InvokeCommand(&sSession, CMD_CALCULATE_LM, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("InvokeCommand ret = 0x%x", ret);
return ret;
}
int tee_compareR0(uint8_t *r0, uint32_t len)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameters
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
uint8_t *share_buffer = (uint8_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_COMPARE_R0;
tci->message.cmdHDCP.cmdBody.cmdHDCPCompare.rx_val_len = len;
memcpy(share_buffer + TCI_LENGTH, r0, len);
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH + len;
ret = TEEC_InvokeCommand(&sSession, CMD_COMPARE_R0, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("InvokeCommand ret = 0x%x", ret);
return ret;
}
int tee_hdcp1x_ComputeCompareV(uint8_t *cryptoParam, uint32_t paramLen,
uint8_t *rxV)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameters
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
uint8_t *share_buffer = (uint8_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_COMPARE_V1;
tci->message.cmdHDCP.cmdBody.cmdHDCPCompare.rx_val_len = 20;
tci->message.cmdHDCP.cmdBody.cmdHDCPCompare.param_len = paramLen;
memcpy(share_buffer + TCI_LENGTH, rxV, 20);
memcpy(share_buffer + TCI_LENGTH + 20, cryptoParam, paramLen);
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH + paramLen + 20;
ret = TEEC_InvokeCommand(&sSession, CMD_COMPARE_V1, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("InvokeCommand ret = 0x%x", ret);
return ret;
}
/**** V2.X****/
int tee_akeCertificate(uint8_t *certificate, bool *bStored, uint8_t *out_m,
uint8_t *out_ekm)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameters
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_AKE_CERTIFICATE;
memcpy(tci->message.cmdHDCP.cmdBody.cmdHDCPAKECertificate.certification,
certificate, CERT_LEN);
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH;
ret = TEEC_InvokeCommand(&sSession, CMD_AKE_CERTIFICATE, &op, NULL);
if (ret != TEEC_SUCCESS) {
TLCERR("InvokeCommand ret = 0x%x", ret);
return ret;
}
TLCINFO("verify signature: result %d", ret);
*bStored = tci->message.cmdHDCP.cmdBody.cmdHDCPAKECertificate.bStored;
memcpy(out_m, tci->message.cmdHDCP.cmdBody.cmdHDCPAKECertificate.m,
M_LEN);
memcpy(out_ekm, tci->message.cmdHDCP.cmdBody.cmdHDCPAKECertificate.ekm,
EKM_LEN);
return ret;
}
int tee_encRsaesOaep(uint8_t *ekm)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameters
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_ENC_KM;
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH;
ret = TEEC_InvokeCommand(&sSession, CMD_ENC_KM, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("InvokeCommand ret = 0x%x", ret);
memcpy(ekm, tci->message.cmdHDCP.cmdBody.cmdHDCPEncKm.encKm,
ENC_KM_LEN);
return ret;
}
int tee_akeHPrime(uint8_t *rtx, uint8_t *rrx, uint8_t *rxCaps, uint8_t *txCaps,
uint8_t *rxH, uint32_t rxH_len)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameters
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
uint8_t *share_buffer = (uint8_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_AKE_H_PRIME;
tci->message.cmdHDCP.cmdBody.cmdHDCPAKEHPrime.rxH_len = rxH_len;
memcpy(tci->message.cmdHDCP.cmdBody.cmdHDCPAKEHPrime.rtx, rtx, RXX_LEN);
memcpy(tci->message.cmdHDCP.cmdBody.cmdHDCPAKEHPrime.rrx, rrx, RXX_LEN);
memcpy(tci->message.cmdHDCP.cmdBody.cmdHDCPAKEHPrime.rxCaps, rxCaps,
CAPS_LEN);
memcpy(tci->message.cmdHDCP.cmdBody.cmdHDCPAKEHPrime.txCaps, txCaps,
CAPS_LEN);
memcpy(share_buffer + TCI_LENGTH, rxH, rxH_len);
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH + rxH_len;
ret = TEEC_InvokeCommand(&sSession, CMD_AKE_H_PRIME, &op, NULL);
if (ret != TEEC_SUCCESS) {
TLCERR("InvokeCommand ret = 0x%x", ret);
return ret;
}
return tci->message.cmdHDCP.responseHeader.returnCode;
}
int tee_akeParing(uint8_t *rx_ekm)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameters
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_AKE_PARING;
memcpy(tci->message.cmdHDCP.cmdBody.cmdHDCPAKEParing.ekm, rx_ekm,
EKM_LEN);
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH;
ret = TEEC_InvokeCommand(&sSession, CMD_AKE_PARING, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("InvokeCommand ret = 0x%x", ret);
return ret;
}
int tee_lcLPrime(uint8_t *rn, uint8_t *rxL, uint32_t len)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameters
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
uint8_t *share_buffer = (uint8_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_LC_L_PRIME;
memcpy(tci->message.cmdHDCP.cmdBody.cmdHDCPLcLPrime.rn, rn, RN_LEN);
tci->message.cmdHDCP.cmdBody.cmdHDCPLcLPrime.rxL_len = len;
memcpy(share_buffer + TCI_LENGTH, rxL, len);
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH + len;
ret = TEEC_InvokeCommand(&sSession, CMD_LC_L_PRIME, &op, NULL);
if (ret != TEEC_SUCCESS) {
TLCERR("InvokeCommand ret = 0x%x", ret);
return ret;
}
return tci->message.cmdHDCP.responseHeader.returnCode;
}
int tee_skeEncKs(uint8_t *riv, uint8_t *eks)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameters
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
uint8_t *share_buffer = (uint8_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_SKE_CAL_EKS;
memcpy(tci->message.cmdHDCP.cmdBody.cmdHDCPSKEEks.riv, riv, RIV_LEN);
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH + 16;
ret = TEEC_InvokeCommand(&sSession, CMD_SKE_CAL_EKS, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("InvokeCommand ret = 0x%x", ret);
memcpy(eks, share_buffer + TCI_LENGTH, 16);
return ret;
}
int tee_hdcp2_ComputeCompareV(uint8_t *cryptoParam, uint32_t paramLen,
uint8_t *rxV, uint8_t *txV)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameters
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
uint8_t *share_buffer = (uint8_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_COMPARE_V2;
tci->message.cmdHDCP.cmdBody.cmdHDCPCompare.rx_val_len = 16;
tci->message.cmdHDCP.cmdBody.cmdHDCPCompare.param_len = paramLen;
memcpy(share_buffer + TCI_LENGTH, rxV, 16);
memcpy(share_buffer + TCI_LENGTH + 16, cryptoParam, paramLen);
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH + paramLen + 16;
ret = TEEC_InvokeCommand(&sSession, CMD_COMPARE_V2, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("InvokeCommand ret = 0x%x", ret);
else
memcpy(txV, share_buffer + TCI_LENGTH, 16);
return ret;
}
int tee_hdcp2_ComputeCompareM(uint8_t *cryptoParam, uint32_t paramLen,
uint8_t *rxM)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameters
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
uint8_t *share_buffer = (uint8_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_COMPARE_M;
tci->message.cmdHDCP.cmdBody.cmdHDCPCompare.rx_val_len = 32;
tci->message.cmdHDCP.cmdBody.cmdHDCPCompare.param_len = paramLen;
memcpy(share_buffer + TCI_LENGTH, rxM, 32);
memcpy(share_buffer + TCI_LENGTH + 32, cryptoParam, paramLen);
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH + paramLen + 32;
ret = TEEC_InvokeCommand(&sSession, CMD_COMPARE_M, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("InvokeCommand ret = 0x%x", ret);
return ret;
}
int tee_loadHdcpKeyById(uint32_t version)
{
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation sOperation;
struct TEEC_Context context;
struct TEEC_Session session;
uint32_t keyID = 0;
switch (version) {
case HDCP_VERSION_1X:
keyID = HDCP_1X_TX_ID;
break;
case HDCP_VERSION_2X:
keyID = HDCP_2X_TX_ID;
break;
default:
TLCERR("Version not support %d", version);
return TEEC_ERROR_NOT_SUPPORTED;
}
/* Create Device context */
ret = TEEC_InitializeContext(NULL, &context);
if (ret != TEEC_SUCCESS) {
TLCERR("load key ret = 0x%x", ret);
return ret;
}
memset(&sOperation, 0, sizeof(struct TEEC_Operation));
sOperation.paramTypes = 0;
ret = TEEC_OpenSession(&context,
&session, /* OUT session */
&KI_TA_UUID, /* destination UUID */
TEEC_LOGIN_PUBLIC, /* connectionMethod */
NULL, /* connectionData */
&sOperation, /* IN OUT operation */
NULL /* OUT returnOrigin, optional */
);
if (ret != TEEC_SUCCESS) {
TLCERR("load key ret = 0x%x", ret);
TEEC_FinalizeContext(&context);
return ret;
}
memset(&sOperation, 0, sizeof(struct TEEC_Operation));
sOperation.paramTypes = TEEC_PARAM_TYPES(
TEEC_VALUE_INPUT,
TEEC_NONE,
TEEC_NONE,
TEEC_NONE);
sOperation.params[0].value.a = keyID;
ret = TEEC_InvokeCommand(&session,
TZCMD_DRMKEY_LOAD_HDCPKEY,
&sOperation, /* IN OUT operation */
NULL /* OUT returnOrigin, optional */
);
TEEC_CloseSession(&session);
TEEC_FinalizeContext(&context);
return ret;
}
/*for test and need remove in furture*/
int tee_hdcp1x_setKey(uint8_t *key)
{
#ifdef HDCP_SETKEY_FROM_KERNEL
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameters
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
uint8_t *share_buffer = (uint8_t *)sSharedMemoryMain.buffer;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_LOAD_KEY;
tci->message.cmdHDCP.cmdBody.cryptokeys.type = TYPE_HDCP13_KEY;
tci->message.cmdHDCP.cmdBody.cryptokeys.len = 289;
memcpy(share_buffer + TCI_LENGTH, key, 289);
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH + 289;
ret = TEEC_InvokeCommand(&sSession, CMD_LOAD_KEY, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("InvokeCommand ret = 0x%x", ret);
return ret;
#else
return TEEC_SUCCESS;
#endif
}
int tee_hdcp2_setKey(uint8_t *kpubdcp, uint8_t *lc128)
{
#ifdef HDCP_SETKEY_FROM_KERNEL
uint32_t ret = TEEC_SUCCESS;
struct TEEC_Operation op;
// Copy parameters
struct tci_t *tci = (struct tci_t *)sSharedMemoryMain.buffer;
uint8_t *share_buffer = (uint8_t *)sSharedMemoryMain.buffer;
uint32_t len = 385 + 16;
memset(tci, 0, TCI_LENGTH);
tci->message.cmdHDCP.commandHeader.commandId = CMD_LOAD_KEY;
tci->message.cmdHDCP.cmdBody.cryptokeys.type = TYPE_HDCP22_KEY;
tci->message.cmdHDCP.cmdBody.cryptokeys.len = len;
memcpy(share_buffer + TCI_LENGTH, kpubdcp, 385);
memcpy(share_buffer + TCI_LENGTH + 385, lc128, 16);
memset(&op, 0, sizeof(struct TEEC_Operation));
op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE,
TEEC_NONE, TEEC_NONE);
op.params[0].memref.parent = &sSharedMemoryMain;
op.params[0].memref.size = TCI_LENGTH + len;
ret = TEEC_InvokeCommand(&sSession, CMD_LOAD_KEY, &op, NULL);
if (ret != TEEC_SUCCESS)
TLCERR("InvokeCommand ret = 0x%x", ret);
return ret;
#else
return TEEC_SUCCESS;
#endif
}
+295
View File
@@ -0,0 +1,295 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __TLCDPHDCP_H__
#define __TLCDPHDCP_H__
#include <linux/printk.h>
#include "tci.h"
#include "tlDPHdcpCMD.h"
#define TLCINFO(string, args...) pr_info("[TLC_HDCP]info: "string, ##args)
#define TLCERR(string, args...) pr_info("[TLC_HDCP]line:%d,err:%s:"string,\
__LINE__, __func__, ##args)
#define RET_ERROR_KEY_INVALID 10
#define RET_SUCCESS 0
/**
* hdcp version definitions
*/
#define HDCP_NONE 0x0 // No HDCP supported, no secure data path
#define HDCP_V1 0x1 // HDCP version 1.0
#define HDCP_V2 0x2 // HDCP version 2.0 Type 1
#define HDCP_V2_1 0x3 // HDCP version 2.1 Type 1
#define HDCP_V2_2 0x4 // HDCP version 2.2 Type 1
#define HDCP_V2_3 0x5 // HDCP version 2.3 Type 1
// Local display only(content required version use only)
#define HDCP_LOCAL_DISPLAY_ONLY 0xf
#define HDCP_NO_DIGITAL_OUTPUT 0xff // No digital output
#define HDCP_DEFAULT HDCP_NO_DIGITAL_OUTPUT // Default value
#define HDCP_VERSION_1X 1
#define HDCP_VERSION_2X 2
#ifdef __cplusplus
extern "C"
{
#endif
/*
*Description:
* A device connect and do some initializations.
*
*Input:
* version: HDCP version
*
*Returns:
* TEEC_SUCCESS success*
*/
int tee_addDevice(uint32_t version);
/*
*Description:
* Device disconnect.
*
*Parameters:
* N/A
*
*Returns:
* N/A
*/
void tee_removeDevice(void);
/*
*Description:
* Clearing paring info.
*
*Parameters:
* N/A
*
*Returns:
* TEEC_SUCCESS success*
*/
int tee_clearParing(void);
/*
*Description:
* Calculate Km base on Bksv and write it to HW.
*
*Input:
* Bksv[5] input
*
*Returns:
* TEEC_SUCCESS success
*/
int tee_calculateLm(uint8_t *Bksv);
/*
*Description:
* Get Aksv from TEE.
*
*Output:
* Aksv[5]
*
*Returns:
* TEEC_SUCCESS success
*/
int tee_getAksv(uint8_t *Aksv);
/*
*Description:
* Get R0 from HW and compare to Rx_r0.
*
*Parameters:
* r0[len] input
*
*Returns:
* TEEC_SUCCESS success
*/
int tee_compareR0(uint8_t *r0, uint32_t len);
/*
*Description:
* Compute and compare V value.
*
*Input:
* cryptoParam[paramLen] params used to calculate
* rxV[20] V value from Rx
*
*Returns:
* RET_COMPARE_PASS verify pass
*/
int tee_hdcp1x_ComputeCompareV(uint8_t *cryptoParam, uint32_t paramLen,
uint8_t *rxV);
/*
*Description:
* Write An to HW.
*
*Input:
* an_code[8]
*
*Returns:
* TEEC_SUCCESS success
*/
int tee_hdcp1x_setTxAn(uint8_t *an_code);
/*
*Description:
* Write RST to HW.
*
*Returns:
* TEEC_SUCCESS success
*/
int tee_hdcp1x_softRst(void);
int tee_hdcp2_softRst(void);
/*
*Description:
* Set enable or disable to HW.
*
*Returns:
* TEEC_SUCCESS success
*/
int tee_hdcp_enableEncrypt(bool bEnable, uint8_t version);
/*
*Description:
* AKE cetificate verify.
*
*Input:
* certificate[522]: cert use to calculate
*output:
* bStored: whether be stored before
* out_m[16]
* out_ekm[16]
*
*Returns:
* TEEC_SUCCESS success*
*/
int tee_akeCertificate(uint8_t *certificate, bool *bStored,
uint8_t *out_m, uint8_t *out_ekm);
/*
*Description:
* Encrypt Km.
*
*Output:
* ekm[128]: encrypted km
*
*Returns:
* TEEC_SUCCESS success*
*/
int tee_encRsaesOaep(uint8_t *ekm);
/*
*Description:
* Calculate H prime and compare to rxH
*
*Input:
* rtx[8]
* rrx[8]
* rxCaps[3]
* txCaps[3]
* rxH[rxH_len]
*
*Returns:
* RET_COMPARE_PASS: compare pass
*/
int tee_akeHPrime(uint8_t *rtx, uint8_t *rrx, uint8_t *rxCaps, uint8_t *txCaps,
uint8_t *rxH, uint32_t rxH_len);
/*
*Description:
* Store paring info.
*
*Input:
* rx_ekm[16]
*
*Returns:
* TEEC_SUCCESS success*
*/
int tee_akeParing(uint8_t *rx_ekm);
/*
*Description:
* Calculate L prime and compare.
*
*Input:
* rn[8]
* rxL[len]
*
*Returns:
* RET_COMPARE_PASS compare pass
*/
int tee_lcLPrime(uint8_t *rn, uint8_t *rxL, uint32_t len);
/*
*Description:
* Encrypt ks
* Write contentkey and riv to hw
*
*Input:
* riv[8]
*Output:
* eks[16]
*
*Returns:
* TEEC_SUCCESS success*
*/
int tee_skeEncKs(uint8_t *riv, uint8_t *eks);
/*
*Description:
* Calculate and compare V prime for repeater.
*
*Input:
* cryptoParam[paramLen] params used to calculate
* rxV[16] V value from Rx
*Output:
* txV[16]
*
*Returns:
* TEEC_SUCCESS success*
*/
int tee_hdcp2_ComputeCompareV(uint8_t *cryptoParam, uint32_t paramLen,
uint8_t *rxV, uint8_t *txV);
/*
*Description:
* Calculate and compare M prime for repeater.
*
*Input:
* cryptoParam[paramLen] params used to calculate
* rxM[32] M value from Rx
*
*Returns:
* RET_COMPARE_PASS verify pass
*/
int tee_hdcp2_ComputeCompareM(uint8_t *cryptoParam, uint32_t paramLen,
uint8_t *rxM);
/*
*Description:
* Get key from Keyinstall.
*
*Input:
* keyID
*
*Returns:
* TEEC_SUCCESS success*
*/
int tee_loadHdcpKeyById(uint32_t version);
/*for test and need remove in furture*/
int tee_hdcp1x_setKey(uint8_t *key);
int tee_hdcp2_setKey(uint8_t *kpubdcp, uint8_t *lc128);
#ifdef __cplusplus
}
#endif
#endif //__TLCDPHDCP_H__