lightduer_ota_updater.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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_updater.h
  18. * Auth: Zhong Shuai (zhongshuai@baidu.com)
  19. * Desc: OTA Updater Head File
  20. */
  21. #ifndef BAIDU_DUER_LIGHTDUER_INCLUDE_LIGHTDUER_OTA_UPDATER_H
  22. #define BAIDU_DUER_LIGHTDUER_INCLUDE_LIGHTDUER_OTA_UPDATER_H
  23. #include "lightduer_ota_unpacker.h"
  24. #include "lightduer_ota_downloader.h"
  25. #include "mbedtls/md5.h"
  26. #define TRANSACTION_LEN (65)
  27. #define VERSION_LEN (16)
  28. #define SIGNATURE_LEN (129)
  29. #define MD5_LEN (16)
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. typedef enum _duer_ota_switch {
  34. ENABLE_OTA = 1,
  35. DISABLE_OTA = -1,
  36. } duer_ota_switch;
  37. typedef enum _duer_ota_reboot {
  38. ENABLE_REBOOT = 1,
  39. DISABLE_REBOOT = -1,
  40. } duer_ota_reboot;
  41. typedef struct _duer_ota_update_command_s {
  42. char transaction[TRANSACTION_LEN + 1];
  43. char version[VERSION_LEN + 1];
  44. char old_version[VERSION_LEN + 1];
  45. char url[URL_LEN + 1];
  46. char signature[SIGNATURE_LEN + 1];
  47. unsigned int size;
  48. } duer_ota_update_command_t;
  49. typedef struct _duer_ota_updater_s {
  50. int id;
  51. duer_ota_unpacker_t *unpacker;
  52. duer_ota_downloader_t *downloader;
  53. duer_ota_update_command_t *update_cmd;
  54. int received_data_size;
  55. int progress;
  56. mbedtls_md5_context md5_ctx;
  57. } duer_ota_updater_t;
  58. typedef struct _duer_ota_init_ops_s {
  59. /*
  60. * Call duer_ota_installer_register_installer() to register the
  61. * OTA installer
  62. */
  63. int (*register_installer)(void);
  64. /*
  65. * Unregister OTA installer
  66. */
  67. int (*unregister_installer)(void);
  68. /*
  69. * Implement reboot system function
  70. */
  71. int (*reboot)(void *arg);
  72. } duer_ota_init_ops_t;
  73. typedef void (*OTA_Updater)(int arg, void *update_cmd);
  74. /*
  75. * Call it to initialize the OTA module
  76. *
  77. * @param ops: You need to implement the structure OTAInitOps
  78. *
  79. * @return int: Success: DUER_OK
  80. * Failed: Other
  81. */
  82. extern int duer_init_ota(duer_ota_init_ops_t const *ops);
  83. /*
  84. * User Call it to enable/disable OTA
  85. *
  86. * @param ops: You need to implement the structure OTAInitOps
  87. *
  88. * @return int: Success: DUER_OK
  89. * Failed: Other
  90. */
  91. extern int duer_ota_set_switch(duer_ota_switch flag);
  92. /*
  93. * Get the OTA status
  94. *
  95. * @param void:
  96. *
  97. * @return int: Enable 1
  98. * Disable -1
  99. */
  100. extern int duer_ota_get_switch(void);
  101. /*
  102. * Set the OTA reboot status
  103. *
  104. * @param void:
  105. *
  106. * @return int: Enable 1
  107. * Disable -1
  108. */
  109. extern int duer_ota_set_reboot(duer_ota_reboot reboot);
  110. /*
  111. * get the OTA reboot status
  112. *
  113. * @param void:
  114. *
  115. * @return int: Enable 1
  116. * Disable -1
  117. */
  118. extern int duer_ota_get_reboot(void);
  119. /*
  120. * get the OTA update command
  121. *
  122. * @param void:
  123. *
  124. * @return Success: duer_ota_update_command_t const *
  125. * Failed: NULL
  126. */
  127. extern duer_ota_update_command_t const *duer_ota_get_update_cmd(void);
  128. /*
  129. * Create a OTA updater to update the firmware
  130. *
  131. * @param update_cmd: Update command
  132. *
  133. * @return int: Success: DUER_OK
  134. * Failed: Other
  135. */
  136. extern int duer_ota_update_firmware(duer_ota_update_command_t const *update_cmd);
  137. #ifdef __cplusplus
  138. }
  139. #endif
  140. #endif // BAIDU_DUER_LIGHTDUER_INCLUDE_LIGHTDUER_OTA_UPDATER_H