tlcDpHdcp.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 __TLCDPHDCP_H__
  14. #define __TLCDPHDCP_H__
  15. #include <linux/printk.h>
  16. #include "tci.h"
  17. #include "tlDPHdcpCMD.h"
  18. #define TLCINFO(string, args...) pr_info("[TLC_HDCP]info: "string, ##args)
  19. #define TLCERR(string, args...) pr_info("[TLC_HDCP]line:%d,err:%s:"string,\
  20. __LINE__, __func__, ##args)
  21. #define RET_ERROR_KEY_INVALID 10
  22. #define RET_SUCCESS 0
  23. /**
  24. * hdcp version definitions
  25. */
  26. #define HDCP_NONE 0x0 // No HDCP supported, no secure data path
  27. #define HDCP_V1 0x1 // HDCP version 1.0
  28. #define HDCP_V2 0x2 // HDCP version 2.0 Type 1
  29. #define HDCP_V2_1 0x3 // HDCP version 2.1 Type 1
  30. #define HDCP_V2_2 0x4 // HDCP version 2.2 Type 1
  31. #define HDCP_V2_3 0x5 // HDCP version 2.3 Type 1
  32. // Local display only(content required version use only)
  33. #define HDCP_LOCAL_DISPLAY_ONLY 0xf
  34. #define HDCP_NO_DIGITAL_OUTPUT 0xff // No digital output
  35. #define HDCP_DEFAULT HDCP_NO_DIGITAL_OUTPUT // Default value
  36. #define HDCP_VERSION_1X 1
  37. #define HDCP_VERSION_2X 2
  38. #ifdef __cplusplus
  39. extern "C"
  40. {
  41. #endif
  42. /*
  43. *Description:
  44. * A device connect and do some initializations.
  45. *
  46. *Input:
  47. * version: HDCP version
  48. *
  49. *Returns:
  50. * TEEC_SUCCESS success*
  51. */
  52. int tee_addDevice(uint32_t version);
  53. /*
  54. *Description:
  55. * Device disconnect.
  56. *
  57. *Parameters:
  58. * N/A
  59. *
  60. *Returns:
  61. * N/A
  62. */
  63. void tee_removeDevice(void);
  64. /*
  65. *Description:
  66. * Clearing paring info.
  67. *
  68. *Parameters:
  69. * N/A
  70. *
  71. *Returns:
  72. * TEEC_SUCCESS success*
  73. */
  74. int tee_clearParing(void);
  75. /*
  76. *Description:
  77. * Calculate Km base on Bksv and write it to HW.
  78. *
  79. *Input:
  80. * Bksv[5] input
  81. *
  82. *Returns:
  83. * TEEC_SUCCESS success
  84. */
  85. int tee_calculateLm(uint8_t *Bksv);
  86. /*
  87. *Description:
  88. * Get Aksv from TEE.
  89. *
  90. *Output:
  91. * Aksv[5]
  92. *
  93. *Returns:
  94. * TEEC_SUCCESS success
  95. */
  96. int tee_getAksv(uint8_t *Aksv);
  97. /*
  98. *Description:
  99. * Get R0 from HW and compare to Rx_r0.
  100. *
  101. *Parameters:
  102. * r0[len] input
  103. *
  104. *Returns:
  105. * TEEC_SUCCESS success
  106. */
  107. int tee_compareR0(uint8_t *r0, uint32_t len);
  108. /*
  109. *Description:
  110. * Compute and compare V value.
  111. *
  112. *Input:
  113. * cryptoParam[paramLen] params used to calculate
  114. * rxV[20] V value from Rx
  115. *
  116. *Returns:
  117. * RET_COMPARE_PASS verify pass
  118. */
  119. int tee_hdcp1x_ComputeCompareV(uint8_t *cryptoParam, uint32_t paramLen,
  120. uint8_t *rxV);
  121. /*
  122. *Description:
  123. * Write An to HW.
  124. *
  125. *Input:
  126. * an_code[8]
  127. *
  128. *Returns:
  129. * TEEC_SUCCESS success
  130. */
  131. int tee_hdcp1x_setTxAn(uint8_t *an_code);
  132. /*
  133. *Description:
  134. * Write RST to HW.
  135. *
  136. *Returns:
  137. * TEEC_SUCCESS success
  138. */
  139. int tee_hdcp1x_softRst(void);
  140. int tee_hdcp2_softRst(void);
  141. /*
  142. *Description:
  143. * Set enable or disable to HW.
  144. *
  145. *Returns:
  146. * TEEC_SUCCESS success
  147. */
  148. int tee_hdcp_enableEncrypt(bool bEnable, uint8_t version);
  149. /*
  150. *Description:
  151. * AKE cetificate verify.
  152. *
  153. *Input:
  154. * certificate[522]: cert use to calculate
  155. *output:
  156. * bStored: whether be stored before
  157. * out_m[16]
  158. * out_ekm[16]
  159. *
  160. *Returns:
  161. * TEEC_SUCCESS success*
  162. */
  163. int tee_akeCertificate(uint8_t *certificate, bool *bStored,
  164. uint8_t *out_m, uint8_t *out_ekm);
  165. /*
  166. *Description:
  167. * Encrypt Km.
  168. *
  169. *Output:
  170. * ekm[128]: encrypted km
  171. *
  172. *Returns:
  173. * TEEC_SUCCESS success*
  174. */
  175. int tee_encRsaesOaep(uint8_t *ekm);
  176. /*
  177. *Description:
  178. * Calculate H prime and compare to rxH
  179. *
  180. *Input:
  181. * rtx[8]
  182. * rrx[8]
  183. * rxCaps[3]
  184. * txCaps[3]
  185. * rxH[rxH_len]
  186. *
  187. *Returns:
  188. * RET_COMPARE_PASS: compare pass
  189. */
  190. int tee_akeHPrime(uint8_t *rtx, uint8_t *rrx, uint8_t *rxCaps, uint8_t *txCaps,
  191. uint8_t *rxH, uint32_t rxH_len);
  192. /*
  193. *Description:
  194. * Store paring info.
  195. *
  196. *Input:
  197. * rx_ekm[16]
  198. *
  199. *Returns:
  200. * TEEC_SUCCESS success*
  201. */
  202. int tee_akeParing(uint8_t *rx_ekm);
  203. /*
  204. *Description:
  205. * Calculate L prime and compare.
  206. *
  207. *Input:
  208. * rn[8]
  209. * rxL[len]
  210. *
  211. *Returns:
  212. * RET_COMPARE_PASS compare pass
  213. */
  214. int tee_lcLPrime(uint8_t *rn, uint8_t *rxL, uint32_t len);
  215. /*
  216. *Description:
  217. * Encrypt ks
  218. * Write contentkey and riv to hw
  219. *
  220. *Input:
  221. * riv[8]
  222. *Output:
  223. * eks[16]
  224. *
  225. *Returns:
  226. * TEEC_SUCCESS success*
  227. */
  228. int tee_skeEncKs(uint8_t *riv, uint8_t *eks);
  229. /*
  230. *Description:
  231. * Calculate and compare V prime for repeater.
  232. *
  233. *Input:
  234. * cryptoParam[paramLen] params used to calculate
  235. * rxV[16] V value from Rx
  236. *Output:
  237. * txV[16]
  238. *
  239. *Returns:
  240. * TEEC_SUCCESS success*
  241. */
  242. int tee_hdcp2_ComputeCompareV(uint8_t *cryptoParam, uint32_t paramLen,
  243. uint8_t *rxV, uint8_t *txV);
  244. /*
  245. *Description:
  246. * Calculate and compare M prime for repeater.
  247. *
  248. *Input:
  249. * cryptoParam[paramLen] params used to calculate
  250. * rxM[32] M value from Rx
  251. *
  252. *Returns:
  253. * RET_COMPARE_PASS verify pass
  254. */
  255. int tee_hdcp2_ComputeCompareM(uint8_t *cryptoParam, uint32_t paramLen,
  256. uint8_t *rxM);
  257. /*
  258. *Description:
  259. * Get key from Keyinstall.
  260. *
  261. *Input:
  262. * keyID
  263. *
  264. *Returns:
  265. * TEEC_SUCCESS success*
  266. */
  267. int tee_loadHdcpKeyById(uint32_t version);
  268. /*for test and need remove in furture*/
  269. int tee_hdcp1x_setKey(uint8_t *key);
  270. int tee_hdcp2_setKey(uint8_t *kpubdcp, uint8_t *lc128);
  271. #ifdef __cplusplus
  272. }
  273. #endif
  274. #endif //__TLCDPHDCP_H__