lightduer_ota_unpacker.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /**
  2. * Copyright (2017) Baidu Inc. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * File: lightduer_ota_unpacker.h
  18. * Auth: Zhong Shuai (zhongshuai@baidu.com)
  19. * Desc: OTA unpacker Head File
  20. */
  21. #include <stddef.h>
  22. #include <stdint.h>
  23. #include <stdbool.h>
  24. #include "lightduer_ota_verifier.h"
  25. #include "lightduer_ota_installer.h"
  26. #include "lightduer_ota_package_info.h"
  27. #include "lightduer_ota_decompression.h"
  28. #ifndef BAIDU_DUER_LIGHTDUER_INCLUDE_LIGHTDUER_OTA_UNPACKER_H
  29. #define BAIDU_DUER_LIGHTDUER_INCLUDE_LIGHTDUER_OTA_UNPACKER_H
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. typedef enum _duer_ota_unpack_mode_s {
  34. SAVE_PACKAGE_HEADER = 1,
  35. PARSE_PACKAGE_HEADER = 2,
  36. SAVE_META_DATA = 3,
  37. UNZIP_DATA = 4,
  38. UNZIP_DATA_DONE = 5,
  39. PARSE_META_DATA = 6,
  40. GET_OTA_INSTALLER = 7,
  41. UNZIP_MODLE_INFO = 8,
  42. UNZIP_MODLE_DATA = 9,
  43. NOTIFY_OTA_BEGIN = 10,
  44. NOTIFY_OTA_END = 11,
  45. DISTRIBUTE_MODULE_INFO = 12,
  46. DISTRIBUTE_MODULE_DATA = 13,
  47. VERIFY_MODULE_DATA = 14,
  48. PUBLIC_KEY_VERIFICATION = 15,
  49. UPDATE_IMAGE_BEGIN = 16,
  50. UPDATE_IMAGE = 17,
  51. VERIFY_IMAGE = 18,
  52. CANCEL_OTA_UPDATE = 19,
  53. UNPACKER_MODE_MAX = 21,
  54. } duer_ota_unpacker_mode_t;
  55. typedef struct _duer_ota_unpack_state_s {
  56. duer_ota_unpacker_mode_t mode;
  57. size_t received_data_size;
  58. size_t processed_data_size;
  59. size_t decompress_data_size;
  60. size_t used_decompress_data_offset;
  61. size_t used_data_offset;
  62. size_t meta_data_offset;
  63. size_t module_data_offset;
  64. size_t package_header_data_offset;
  65. } duer_ota_unpack_state_t;
  66. typedef struct _duer_ota_unpacker_s {
  67. // Lock the unpacker
  68. duer_mutex_t lock;
  69. duer_ota_verifier_t *verifier;
  70. duer_ota_unpack_state_t state;
  71. duer_ota_package_header_t package_header;
  72. duer_ota_package_basic_info_t basic_info;
  73. duer_ota_package_install_info_t install_info;
  74. void *meta_data;
  75. duer_ota_decompression_t *decompression;
  76. duer_ota_installer_t *installer;
  77. char const *err_msg;
  78. } duer_ota_unpacker_t;
  79. /*
  80. * Create a OTA unpacker
  81. *
  82. * @param void:
  83. *
  84. * @return: Success: duer_ota_unpacker_t *
  85. * Failed: NULL
  86. */
  87. extern duer_ota_unpacker_t *duer_ota_unpacker_create_unpacker(void);
  88. /*
  89. * Destroy a OTA unpacker
  90. *
  91. * @param unpacker: OTA unpacker
  92. *
  93. * @return int: Success: DUER_OK
  94. * Failed: Other
  95. */
  96. extern int duer_ota_unpacker_destroy_unpacker(duer_ota_unpacker_t *unpacker);
  97. /*
  98. * Get the basic information of the package
  99. *
  100. * @param unpacker: OTA unpacker
  101. *
  102. * @return : Success:duer_ota_package_basic_info_t *
  103. * Failed: NULL
  104. */
  105. extern duer_ota_package_basic_info_t const *duer_ota_unpacker_get_package_basic_info(
  106. duer_ota_unpacker_t const *unpacker);
  107. /*
  108. * Get the header information of the package
  109. *
  110. * @param unpacker: OTA unpacker
  111. *
  112. * @return : Success: duer_ota_package_header_t *
  113. * Failed: NULL
  114. */
  115. extern duer_ota_package_header_t const *duer_ota_unpacker_get_package_header_info(
  116. duer_ota_unpacker_t const *unpacker);
  117. /*
  118. * Unpacke a OTA upadate package
  119. *
  120. * @param unpacker: OTA unpacker
  121. * data: data of the package
  122. * size: data size
  123. *
  124. * @return int: Success: DUER_OK
  125. * Failed: Other
  126. */
  127. extern int duer_ota_unpacker_unpack_package(
  128. duer_ota_unpacker_t *unpacker,
  129. uint8_t const *data,
  130. size_t size);
  131. /*
  132. * Set the unpacker mode
  133. *
  134. * @param unpacker: OTA unpacker
  135. * mode: Unpacker mode
  136. *
  137. * @return int: Success: DUER_OK
  138. * Failed: Other
  139. */
  140. extern int duer_ota_unpacker_set_unpacker_mode(
  141. duer_ota_unpacker_t *unpacker,
  142. duer_ota_unpacker_mode_t mode);
  143. /*
  144. * Get the unpacker mode
  145. *
  146. * @param unpacker: OTA unpacker
  147. *
  148. * @return mode: Unpacker mode
  149. */
  150. extern duer_ota_unpacker_mode_t duer_ota_unpacker_get_unpacker_mode(
  151. duer_ota_unpacker_t const *unpacker);
  152. /*
  153. * Get the unpacker error message
  154. *
  155. * @param unpacker: OTA unpacker
  156. *
  157. * @return char const *: Success: error message
  158. * Failed: NULL
  159. */
  160. extern char const *duer_ota_unpacker_get_err_msg(duer_ota_unpacker_t const *unpacker);
  161. #ifdef __cplusplus
  162. }
  163. #endif
  164. #endif // BAIDU_DUER_LIGHTDUER_INCLUDE_LIGHTDUER_OTA_UNPACKER_H