srv_simlock.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _SIM_LOCK_SERV_H
  13. #define _SIM_LOCK_SERV_H
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #include "simlock_type.h"
  18. #include "simlock_storage.h"
  19. // custimize data
  20. typedef struct
  21. {
  22. uint32_t simlock_support;
  23. uint32_t oper_mode;
  24. uint32_t ctrl_key_type;
  25. uint32_t simlock_status;
  26. uint32_t max_num_trials;
  27. NETWORK_LOCKS_T network_locks;
  28. NETWORK_SUBSET_LOCKS_T network_subset_locks;
  29. SP_LOCKS_T sp_locks;
  30. CORPORATE_LOCKS_T corporate_locks;
  31. USER_LOCKS_T user_locks;
  32. } simlock_cust_data_t;
  33. // user data
  34. typedef struct
  35. {
  36. uint32_t simlock_status;
  37. uint32_t nck_trials;
  38. uint32_t nck_unlock_time;
  39. uint32_t nsck_trials;
  40. uint32_t nsck_unlock_time;
  41. uint32_t spck_trials;
  42. uint32_t spck_unlock_time;
  43. uint32_t cck_trials;
  44. uint32_t cck_unlock_time;
  45. uint32_t pck_trials;
  46. uint32_t pck_unlock_time;
  47. } simlock_dynamic_data_t;
  48. typedef struct
  49. {
  50. simlock_dynamic_data_t dynamic_data;
  51. uint32_t dummy[4];
  52. } simlock_user_data_t;
  53. typedef struct
  54. {
  55. uint32_t SIM_lock_status;
  56. uint32_t max_num_trials;
  57. NETWORK_LOCKS_T network_locks;
  58. NETWORK_SUBSET_LOCKS_T network_subset_locks;
  59. SP_LOCKS_T SP_locks;
  60. CORPORATE_LOCKS_T corporate_locks;
  61. USER_LOCKS2_T user_locks;
  62. } srvSimlockData_t;
  63. typedef SIM_LOCK_KEY_T srvSimlockKey_t;
  64. /**
  65. * data structure for PC tool or other clients
  66. */
  67. typedef struct
  68. {
  69. simlock_cust_data_t cust_data;
  70. simlock_encrypt_keys_t encrypt_keys;
  71. uint8_t sign[SL_RSA_SIGN_LEN];
  72. uint8_t enc_user_data[SL_RSA_N_H_LEN];
  73. } simlock_data_t;
  74. /**
  75. * @brief This function is used to save the random number "HUK".
  76. * This number will be used for tool authentication.
  77. * @param data The data of huk.
  78. * @param len the len of huk.
  79. * @return:
  80. * - 0 Write publick failure.
  81. * - 1 Write public success.
  82. */
  83. uint32_t srvSimlockSetHuk(const char *data, uint32_t len);
  84. /**
  85. * @brief This function is used to check and save the RSA public key.
  86. * @param rsa_pubkey The original data of public key.
  87. * @param pubkey_len the len of public key.
  88. * @param sign The signature of public key.
  89. * @param sign_len the len of signtaure.
  90. * @return:
  91. * - 0 Write publick failure.
  92. * - 1 Write public success.
  93. */
  94. uint32_t srvSimlockFacauthPubkey(const char *rsa_pubkey, uint32_t pubkey_len, const char *sign, uint32_t sign_len);
  95. /**
  96. * @brief This function is used to start authentication.
  97. * @param data Output the data is used for authentication.
  98. * @param len the len of ouput data.
  99. * @return:
  100. * - 0 The satrt of Authentication failure.
  101. * - 1 The satrt of Authentication success.
  102. */
  103. uint32_t srvSimlockAuthStart(char *data, uint32_t *len);
  104. /**
  105. * @brief This function is used to end authentication.
  106. * @param data Input the data is used for authentication.
  107. * @param len the len of input data.
  108. * @return:
  109. * - 0 Authentication failure.
  110. * - 1 Authentication success.
  111. */
  112. uint32_t srvSimlockAuthEnd(const char *data, uint32_t len);
  113. /**
  114. * @brief This function is used to encrypt the original simlock keys
  115. * @param data Input the data of simlock keys.
  116. * @param len the len of data of simlock keys.
  117. * @param encrypt_data The return cipher data of simlock keys.
  118. * @param en_len The return len of cipher data.
  119. * @return:
  120. * - 0 Fail to write.
  121. * - 1 Write successfully.
  122. */
  123. uint32_t srvSimlockEncryptKeys(const char *data, uint32_t len, char *encrypt_data, uint32_t en_len);
  124. /**
  125. * @brief Tools write the simlock data to device.
  126. * @param data Input the data of simlock.
  127. * @param len the len of data.
  128. * @return:
  129. * - 0 Fail to write.
  130. * - 1 Write successfully.
  131. */
  132. uint32_t srvSimlockDataProcess(const char *data, uint32_t len);
  133. /**
  134. * @brief Tools write the rsa signature to device.
  135. * @param signed_data Input the signature of simlock data.
  136. * @param len the len of signature.
  137. * @return:
  138. * - 0 Fail to write.
  139. * - 1 Write successfully.
  140. */
  141. uint32_t srvSimlockDdataSha(uint8_t *hash);
  142. /**
  143. * @brief Tools write the rsa signature to device.
  144. * @param signed_data Input the signature of simlock data.
  145. * @param len the len of signature.
  146. * @return:
  147. * - 0 Fail to write.
  148. * - 1 Write successfully.
  149. */
  150. uint32_t srvSimlockSignData(const uint8_t *signed_data, uint32_t len);
  151. /**
  152. * @brief Read simlock data
  153. * @param simlock_data Store the data of user data.
  154. * @return:
  155. */
  156. void srvSimlockGetLocksData(srvSimlockData_t *simlock_data);
  157. /**
  158. * @brief This function is used to init the simlock service.
  159. */
  160. void srvSimlockInit();
  161. #ifdef __cplusplus
  162. }
  163. #endif
  164. #endif // End of _SIM_LOCK_H