ota_internal.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) 2012-2019 UCloud. 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. * A copy of the License is located at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * or in the "license" file accompanying this file. This file is distributed
  11. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. * express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #ifndef C_SDK_OTA_INTERNAL_H_
  16. #define C_SDK_OTA_INTERNAL_H_
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #include <stdint.h>
  21. #include "ota_config.h"
  22. #include "uiot_export_ota.h"
  23. #include "utils_httpc.h"
  24. #include "utils_list.h"
  25. // OTA Signal Channel
  26. typedef void (*OnOTAMessageCallback)(void *pContext, const char *msg, uint32_t msgLen);
  27. typedef struct{
  28. char *payload; // MQTT 消息负载
  29. size_t payload_len; // MQTT 消息负载长度
  30. }OTA_UPLOAD_Msg;
  31. typedef struct {
  32. const char *url;
  33. http_client_t http; /* http client */
  34. http_client_data_t http_data; /* http client data */
  35. } OTA_Http_Client;
  36. void *osc_init(const char *product_sn, const char *device_sn, void *channel, OnOTAMessageCallback callback,
  37. void *context);
  38. /* OSC, OTA signal channel */
  39. typedef struct {
  40. void *mqtt;
  41. const char *product_sn;
  42. const char *device_sn;
  43. char topic_upgrade[OTA_TOPIC_BUF_LEN];
  44. OnOTAMessageCallback msg_callback;
  45. List *msg_list; /* recv update msg */
  46. void *msg_mutex; /* mutex for msg list */
  47. void *context;
  48. } OTA_MQTT_Struct_t;
  49. int osc_deinit(void *handle);
  50. int osc_report_progress(void *handle, const char *msg);
  51. int osc_upstream_publish(void *handle, const char *msg);
  52. // OTA Fetch Channel
  53. void *ofc_init(const char *url);
  54. int32_t ofc_connect(void *handle);
  55. int32_t ofc_fetch(void *handle, uint32_t size_fetched, char *buf, uint32_t buf_len, size_t range_len, uint32_t timeout_s);
  56. int ofc_deinit(void *handle);
  57. // ota_lib
  58. void *ota_lib_md5_init(void);
  59. void ota_lib_md5_update(void *md5, const char *buf, size_t buf_len);
  60. void ota_lib_md5_finalize(void *md5, char *output_str);
  61. void ota_lib_md5_deinit(void *md5);
  62. int ota_lib_get_msg_type(char *json, char **type);
  63. int ota_lib_get_msg_module_ver(char *json, char **module, char **ver);
  64. int ota_lib_get_params(char *json, char **url, char **module, char **download_name, char **version, char **md5,
  65. uint32_t *fileSize);
  66. int ota_lib_gen_upstream_msg(char *buf, size_t bufLen, const char *module, const char *version, int progress,
  67. IOT_OTA_UpstreamMsgType reportType);
  68. #ifdef __cplusplus
  69. }
  70. #endif
  71. #endif //C_SDK_OTA_INTERNAL_H_