keyupdate.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #ifndef KEYUPDATE_H_INCLUDED
  2. #define KEYUPDATE_H_INCLUDED
  3. #include "types.h"
  4. #undef KEYUPDATE_DEBUG
  5. #if 0
  6. #define KEYUPDATE_DEBUG(fmt, args...) do {fprintf(stderr, "[KEYUPDATE] " fmt, ##args);}while(0);
  7. #else
  8. #define KEYUPDATE_DEBUG(fmt, args...)
  9. #endif
  10. #define FILENAME_SIZE 32
  11. #ifdef CONFIG_DISABLE_CIKEY_HDCPKEY_SPI_ENCRYPT
  12. extern void do_spi_decrypt(char *, unsigned int, unsigned int);
  13. #endif
  14. /*******************************************************************************
  15. * enumeration
  16. ******************************************************************************/
  17. typedef enum {
  18. e_MID_STATUS_NO_UPDATE,
  19. e_MID_STATUS_OPEN_FILE_FAILED,
  20. e_MID_STATUS_FORMAT_ERROR,
  21. e_MID_STATUS_UPDATE_SUCCESS,
  22. }e_MID_KEYUPDATE_STATUS;
  23. /*******************************************************************************
  24. * HDCP UPDATE - Constant
  25. ******************************************************************************/
  26. #define DIR_HDCPKEY "s2_hdcp"
  27. #define FILE_EXTENSION_HDCPKEY ".bin"
  28. /*******************************************************************************
  29. * HDCP UPDATE - APIs
  30. ******************************************************************************/
  31. /*******************************************************************************************/
  32. /**
  33. * \fn e_MID_KEYUPDATE_STATUS MID_KEYUPDATE_HDCP_Update.
  34. *
  35. * \param pBuffer : The storage that carrys the data which will be updated to flash.
  36. * size_buffer : The size of Buffer.
  37. *
  38. * \return e_MID_STATUS_UPDATE_SUCCESS if update flash successful, warning or error code if function failed
  39. *
  40. * \note Description : Update HDCP KEY to flash, and the keys should be encrypt to 588 bytes format.
  41. *
  42. ********************************************************************************************/
  43. e_MID_KEYUPDATE_STATUS MID_KEYUPDATE_HDCP_Update(UINT8 *pBuffer, UINT32 size_buffer);
  44. /*******************************************************************************************/
  45. /**
  46. * \fn e_MID_KEYUPDATE_STATUS MID_KEYUPDATE_HDCP_Update_ByFile.
  47. *
  48. * \param pFileName : The file that carrys the data which will be updated to flash.
  49. *
  50. * \return e_MID_STATUS_UPDATE_SUCCESS if update flash successful, warning or error code if function failed
  51. *
  52. * \note Description : Update HDCP KEY to flash, and the keys should be encrypt to 588 bytes format.
  53. *
  54. ********************************************************************************************/
  55. #ifndef CONFIG_EXTIC_STORAGE_DEVICE
  56. e_MID_KEYUPDATE_STATUS MID_KEYUPDATE_HDCP_Update_ByFile(char *pFileName);
  57. #else
  58. e_MID_KEYUPDATE_STATUS MID_KEYUPDATE_HDCP_Update_ToFlash_ByFile(char *pFileName, char **pBuffer1, int* size_file);
  59. e_MID_KEYUPDATE_STATUS MID_KEYUPDATE_HDCP_Update_NoticeHDMI_RemoveFile(char *pFileName);
  60. #endif
  61. /*******************************************************************************************/
  62. /**
  63. * \fn UINT32 MID_KEYUPDATE_HDCP_Get_Flash_Checksum.
  64. *
  65. * \param None.
  66. *
  67. * \return The 4-bytes checksum. If data error will be return 0.
  68. *
  69. * \note Description : The HDCP key checksum which is encrypted to 588-bytes format.
  70. *
  71. ********************************************************************************************/
  72. UINT32 MID_KEYUPDATE_HDCP_Get_Flash_Checksum(void);
  73. /*******************************************************************************
  74. * CI+ UPDATE - Constant
  75. ******************************************************************************/
  76. #define DIR_CIPLUS "s2_ciplus"
  77. #define FILE_EXTENSION_CIPLUS ".bin"
  78. /*******************************************************************************
  79. * CI+ UPDATE - APIs
  80. ******************************************************************************/
  81. /*******************************************************************************************/
  82. /**
  83. * \fn e_MID_KEYUPDATE_STATUS MID_KEYUPDATE_CIPlus_Update.
  84. *
  85. * \param pBuffer : The storage that carrys the data which will be updated to flash.
  86. * size_buffer : The size of Buffer.
  87. *
  88. * \return e_MID_STATUS_UPDATE_SUCCESS if update flash successful, warning or error code if function failed
  89. *
  90. * \note Description : Update CI+ KEY to flash, and the keys should be encrypt to 10K bytes format.
  91. *
  92. ********************************************************************************************/
  93. e_MID_KEYUPDATE_STATUS MID_KEYUPDATE_CIPlus_Update(UINT8 *pBuffer, UINT32 size_buffer);
  94. /*******************************************************************************************/
  95. /**
  96. * \fn e_MID_KEYUPDATE_STATUS MID_KEYUPDATE_CIPLUS_Update_ByFile.
  97. *
  98. * \param pFileName : The file that carrys the data which will be updated to flash.
  99. *
  100. * \return e_MID_STATUS_UPDATE_SUCCESS if update flash successful, warning or error code if function failed
  101. *
  102. * \note Description : Update CI+ KEY to flash, and the keys should be encrypt to 10K bytes format.
  103. *
  104. ********************************************************************************************/
  105. e_MID_KEYUPDATE_STATUS MID_KEYUPDATE_CIPLUS_Update_ByFile(char *pFileName);
  106. UINT8 *MID_CIKEYUPDATE_Get_File_byOrder(char *pdirpath, char*pfile_extension);
  107. UINT8 *MID_HDCPKEYUPDATE_Get_File_byOrder(char *pdirpath, char*pfile_extension);
  108. /*******************************************************************************************/
  109. /**
  110. * \fn UINT32 MID_KEYUPDATE_CIPlus_Get_Flash_Checksum.
  111. *
  112. * \param None.
  113. *
  114. * \return The 4-bytes checksum. If data error will be return 0.
  115. *
  116. * \note Description : The CI+ key checksum which is encrypted to 10K-bytes format.
  117. *
  118. ********************************************************************************************/
  119. UINT32 MID_KEYUPDATE_CIPlus_Get_Flash_Checksum(void);
  120. /*******************************************************************************
  121. * Common - APIs
  122. ******************************************************************************/
  123. /*******************************************************************************************/
  124. /**
  125. * \fn UINT8 *MID_KEYUPDATE_Get_File.
  126. *
  127. * \param pdirpath : the specific directory path.
  128. * pfile_extension : the specific file extension.
  129. *
  130. * \return The file which name is end by the specific file extension. If not match, return NULL.
  131. *
  132. * \note Description : Search the file on specific dir. path.
  133. * And return the first file which name must be end by specific file extension.
  134. ********************************************************************************************/
  135. UINT8 *MID_KEYUPDATE_Get_File(char *pdirpath, char*pfile_extension);
  136. UINT8 *MID_KEYUPDATE_Get_File_byOrder(char *pdirpath, char*pfile_extension);
  137. /*******************************************************************************************/
  138. /**
  139. * \fn UINT8 MID_KEYUPATE_Remove_File.
  140. *
  141. * \param pFileName : The file name.
  142. *
  143. * \return Return 0, if remove failed. Others, remove success.
  144. *
  145. * \note Description : Remove specific file.
  146. *
  147. ********************************************************************************************/
  148. UINT8 MID_KEYUPATE_Remove_File(char *pFileName);
  149. /*******************************************************************************************/
  150. /**
  151. * \fn UINT8 MID_KEYUPDATE_HDCP_IsKeyValid
  152. *
  153. * \param None.
  154. *
  155. * \return The 1-bytes . If key error will be return false
  156. *
  157. ********************************************************************************************/
  158. UINT8 MID_KEYUPDATE_HDCP_IsKeyValid(void);
  159. /*******************************************************************************************/
  160. /**
  161. * \fn UINT32 MID_KEYUPDATE_CIPlus_Get_KeyFileName.
  162. *
  163. * \param :.Get file name
  164. *
  165. * \return \return The 1-bytes . If error will be return false.
  166. *
  167. * \note Description : The pKEYFileName which is get file name of key.
  168. *
  169. ********************************************************************************************/
  170. UINT8 MID_KEYUPDATE_CIPlus_Get_KeyFileName(char *pKEYFileName);
  171. /*******************************************************************************************/
  172. /**
  173. * \fn UINT32 MID_KEYUPDATE_HDCP_Get_KeyFileName.
  174. *
  175. * \param :.Get file name
  176. *
  177. * \return \return The 1-bytes . If error will be return false.
  178. *
  179. * \note Description : The pKEYFileName which is get file name of key.
  180. *
  181. ********************************************************************************************/
  182. UINT8 MID_KEYUPDATE_HDCP_Get_KeyFileName(char *pKEYFileName);
  183. #ifdef CONFIG_SUPPORT_STORE_HDCP2X_TO_FLASH
  184. UINT8 *MID_HDCP2XKEYUPDATE_Get_File_byOrder(char *pdirpath, char*pfile_extension);
  185. e_MID_KEYUPDATE_STATUS MID_KEYUPDATE_HDCP2X_Update(UINT8 *pBuffer, UINT32 size_buffer);
  186. e_MID_KEYUPDATE_STATUS MID_KEYUPDATE_HDCP2X_Update_ByFile(char *pFileName);
  187. UINT32 MID_KEYUPDATE_HDCP2X_Get_Flash_Checksum(void);
  188. UINT8 MID_KEYUPDATE_HDCP2X_IsKeyValid(void);
  189. #ifdef CONFIG_APPEND_NAME_TO_CIKEY_HDCPKEY
  190. UINT8 MID_KEYUPDATE_HDCP2X_Get_KeyFileName(char *pKEYFileName);
  191. #endif
  192. #endif
  193. #endif // KEYUPDATE_H_INCLUDED