ota_api.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2019 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief OTA backend interface
  9. */
  10. #ifndef __OTA_API_H__
  11. #define __OTA_API_H__
  12. /* support check data checksum in each ota unit */
  13. #define CONFIG_OTA_BT_SUPPORT_UNIT_CRC
  14. #define TLV_TYPE_OTA_SUPPORT_FEATURES 0x09
  15. #define OTA_SUPPORT_FEATURE_UNIT_DATA_CRC (1 << 0)
  16. #define OTA_ERROR_CODE_SUCCESS 100000
  17. #define SERVICE_ID_OTA 0x9
  18. #define OTA_SVC_SEND_BUFFER_SIZE 0x80
  19. #define OTA_UNIT_SIZE 0x100
  20. #define OTA_SVC_TRANS_SEND_BUFFER_SIZE 1024
  21. #define TLV_MAX_DATA_LENGTH 0x3fff
  22. #define TLV_TYPE_ERROR_CODE 0x7f
  23. #define TLV_TYPE_MAIN 0x80
  24. #define OTA_CMD_H2D_REQUEST_UPGRADE 0x01
  25. #define OTA_CMD_H2D_CONNECT_NEGOTIATION 0x02
  26. #define OTA_CMD_D2H_REQUIRE_IMAGE_DATA 0x03
  27. #define OTA_CMD_H2D_SEND_IMAGE_DATA 0x04
  28. #define OTA_CMD_D2H_REPORT_RECEVIED_DATA_COUNT 0x05
  29. #define OTA_CMD_D2H_VALIDATE_IMAGE 0x06
  30. #define OTA_CMD_D2H_REPORT_STATUS 0x07
  31. #define OTA_CMD_D2H_CANCEL_UPGRADE 0x08
  32. #define OTA_CMD_H2D_NEGOTIATION_RESULT 0x09
  33. #define OTA_CMD_D2H_REQUEST_UPGRADE 0x0A
  34. #define OTA_CMD_H2D_SEND_IMAGE_DATA_WITH_CRC 0x0B
  35. #define TLV_TYPE_OTA_WAIT_TIMEOUT 0x01
  36. #define TLV_TYPE_OTA_RESTART_TIMEOUT 0x02
  37. #define TLV_TYPE_OTA_UINT_SIZE 0x03
  38. #define TLV_TYPE_OTA_INTERVAL 0x04
  39. #define TLV_TYPE_OTA_FILE_OFFSET 0x01
  40. #define TLV_TYPE_OTA_FILE_LEN 0x02
  41. #define TLV_TYPE_OTA_APPLY_BITMAP 0x03
  42. #define TLV_TYPE_OTA_VALID_REPORT 0x01
  43. #define TLV_TYPE_OTA_STATUS_CODE 0x7F
  44. enum cli_prot_state{
  45. PROT_STATE_IDLE,
  46. PROT_STATE_DATA,
  47. };
  48. struct cli_prot_context {
  49. u8_t state;
  50. int send_buf_size;
  51. u8_t *send_buf;
  52. u8_t *read_buf;
  53. int read_len;
  54. int read_done_len;
  55. u8_t last_psn;
  56. u8_t host_features;
  57. u16_t app_wait_timeout;
  58. u16_t device_restart_timeout;
  59. u16_t ota_unit_size;
  60. u16_t ota_interval;
  61. u8_t ota_ack_enable;
  62. io_stream_t sppble_stream;
  63. int sppble_stream_opened;
  64. int negotiation_done;
  65. };
  66. #endif /* __OTA_API_H__ */