tci.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * Copyright (c) 2020 MediaTek Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef __TCI_H__
  14. #define __TCI_H__
  15. typedef uint32_t tciCommandId_t;
  16. typedef uint32_t tciResponseId_t;
  17. typedef uint32_t tciReturnCode_t;
  18. typedef uint32_t TEE_VA_TYPE;
  19. #define RET_COMPARE_PASS 0
  20. #define RET_COMPARE_FAIL 1
  21. #define RET_NEW_DEVICE 2
  22. #define RET_STORED_DEVICE 3
  23. #define AN_LEN 8
  24. #define AKSV_LEN 5
  25. #define BKSV_LEN 5
  26. #define CERT_LEN 522
  27. #define EKM_LEN 16
  28. #define M_LEN 16
  29. #define ENC_KM_LEN 128
  30. #define RXX_LEN 8
  31. #define CAPS_LEN 3
  32. #define RN_LEN 8
  33. #define RIV_LEN 8
  34. #define TYPE_HDCP_PARAM_AN 10
  35. #define TYPE_HDCP_PARAM_RST_1 11
  36. #define TYPE_HDCP_PARAM_RST_2 12
  37. #define TYPE_HDCP_ENABLE_ENCRYPT 13
  38. #define TYPE_HDCP_DISABLE_ENCRYPT 14
  39. //for test
  40. #define TYPE_HDCP13_KEY 20
  41. #define TYPE_HDCP22_KEY 21
  42. struct cryptokeys_t {
  43. uint8_t type;
  44. uint32_t len;
  45. TEE_VA_TYPE key;
  46. };
  47. /**
  48. * TCI command header.
  49. */
  50. struct tciCommandHeader_t {
  51. tciCommandId_t commandId;
  52. };
  53. /**
  54. * TCI response header.
  55. */
  56. struct tciResponseHeader_t {
  57. tciResponseId_t responseId;
  58. tciReturnCode_t returnCode;
  59. };
  60. struct cmdHDCPInitForVerion_t {
  61. uint32_t version;
  62. bool needLoadKey;
  63. };
  64. struct cmdHDCPWriteVal_t {
  65. uint8_t type;
  66. uint8_t len;
  67. TEE_VA_TYPE val;
  68. };
  69. struct cmdHDCPCalculateLm_t {
  70. uint8_t bksv[BKSV_LEN];
  71. };
  72. struct cmdHDCPGetAksv_t {
  73. uint8_t aksv[AKSV_LEN];
  74. };
  75. struct cmdHDCPSha1_t {
  76. uint32_t message_len;
  77. TEE_VA_TYPE message_addr;
  78. };
  79. struct cmdHDCPAKECertificate_t {
  80. uint8_t certification[CERT_LEN];
  81. bool bStored;
  82. uint8_t m[M_LEN];
  83. uint8_t ekm[EKM_LEN];
  84. };
  85. struct cmdHDCPAKEParing_t {
  86. uint8_t ekm[EKM_LEN];
  87. };
  88. struct cmdHDCPEncKm_t {
  89. uint8_t encKm[ENC_KM_LEN];
  90. };
  91. struct cmdHDCPAKEHPrime_t {
  92. uint8_t rtx[RXX_LEN];
  93. uint8_t rrx[RXX_LEN];
  94. uint8_t rxCaps[CAPS_LEN];
  95. uint8_t txCaps[CAPS_LEN];
  96. uint32_t rxH_len;
  97. TEE_VA_TYPE rxH;
  98. };
  99. struct cmdHDCPLcLPrime_t {
  100. uint8_t rn[RN_LEN];
  101. uint32_t rxL_len;
  102. TEE_VA_TYPE rxL;
  103. };
  104. struct cmdHDCPSKEEks_t {
  105. uint8_t riv[RIV_LEN];
  106. uint32_t eks_len;
  107. TEE_VA_TYPE eks;
  108. };
  109. struct cmdHDCPCompare_t {
  110. uint32_t rx_val_len;
  111. TEE_VA_TYPE rx_val;
  112. uint32_t param_len;
  113. TEE_VA_TYPE param;
  114. uint32_t out_len;
  115. TEE_VA_TYPE out;
  116. };
  117. union tcicmdBody_t {
  118. /* init with special HDCP version */
  119. struct cmdHDCPInitForVerion_t cmdHDCPInitForVerion;
  120. /* write uint32 data to hw */
  121. struct cmdHDCPWriteVal_t cmdHDCPWriteVal;
  122. /* get aksv */
  123. struct cmdHDCPGetAksv_t cmdHDCPGetAksv;
  124. /* calculate r0 */
  125. struct cmdHDCPCalculateLm_t cmdHDCPCalculateLm;
  126. /* generate signature for certificate*/
  127. struct cmdHDCPAKECertificate_t cmdHDCPAKECertificate;
  128. /* to store ekm*/
  129. struct cmdHDCPAKEParing_t cmdHDCPAKEParing;
  130. /* encrypt km for V2.2 */
  131. struct cmdHDCPEncKm_t cmdHDCPEncKm;
  132. /* compute H prime */
  133. struct cmdHDCPAKEHPrime_t cmdHDCPAKEHPrime;
  134. /* compute L prime */
  135. struct cmdHDCPLcLPrime_t cmdHDCPLcLPrime;
  136. /* compute eks */
  137. struct cmdHDCPSKEEks_t cmdHDCPSKEEks;
  138. /* compare */
  139. struct cmdHDCPCompare_t cmdHDCPCompare;
  140. /* for test only */
  141. struct cryptokeys_t cryptokeys;
  142. } __attribute__ ((__packed__));
  143. struct cmdHDCP_t {
  144. /* request tci header */
  145. struct tciCommandHeader_t commandHeader;
  146. /* response tci header */
  147. struct tciResponseHeader_t responseHeader;
  148. uint32_t drHandle;
  149. union tcicmdBody_t cmdBody;
  150. };
  151. /**
  152. * TCI message data.
  153. * It's union structure
  154. */
  155. union tciMessage_t {
  156. /* request tci include header and other parameters */
  157. struct cmdHDCP_t cmdHDCP;
  158. };
  159. /**
  160. * Overall TCI structure.
  161. */
  162. struct tci_t {
  163. union tciMessage_t message; /**< TCI message */
  164. };
  165. const static uint64_t TCI_LENGTH = sizeof(struct tci_t);
  166. #endif //__TCI_H__