ota_trans.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_TRANS_H__
  11. #define __OTA_TRANS_H__
  12. #define OTA_BACKEND_TYPE_UNKNOWN (0)
  13. #define OTA_TRANS_TYPE_BLUETOOTH (1)
  14. #define OTA_TRANS_IOCTL_REQUEST_UPGRADE (0x10000)
  15. #define OTA_TRANS_IOCTL_CONNECT_NEGOTIATION (0x10001)
  16. #define OTA_TRANS_IOCTL_NEGOTIATION_RESULT (0x10002)
  17. #define OTA_TRANS_IOCTL_SEND_IMAGE (0x10003)
  18. #define OTA_TRANS_IOCTL_UNITSIZE_GET (0x20000)
  19. enum OTA_TRANS_UPGRADE_STATUS
  20. {
  21. OTA_TRANS_STATUS_NULL = 0x0000,
  22. OTA_TRANS_INIT,
  23. OTA_TRANS_SDAP_RESULT,
  24. OTA_TRANS_CONNECTED,
  25. OTA_TRANS_DISCONNECT,
  26. OTA_TRANS_REQUEST_UPGRADE_ACK,
  27. OTA_TRANS_CONNECT_NEGOTIATION_ACK,
  28. OTA_TRANS_NEGOTIATION_RESULT_ACK,
  29. OTA_TRANS_REQUEST_IMAGE_DATA,
  30. OTA_TRANS_VALIDATE_REPORT,
  31. OTA_TRANS_UPGRADE_STATUS_NOTIFY,
  32. };
  33. struct ota_trans;
  34. typedef void (*ota_trans_notify_cb_t)(struct ota_trans *trans, int state, void* param);
  35. /**
  36. * @brief Logger backend API.
  37. */
  38. struct ota_trans_api
  39. {
  40. struct ota_trans * (*init)(ota_trans_notify_cb_t cb, void *init_param);
  41. void (*exit)(struct ota_trans *trans);
  42. int (*open)(struct ota_trans *trans);
  43. int (*read)(struct ota_trans *trans, int offset, void *buf, int size);
  44. int (*ioctl)(struct ota_trans *trans, int cmd, void *param);
  45. int (*close)(struct ota_trans *trans);
  46. };
  47. struct ota_trans {
  48. struct ota_trans_api *api;
  49. int type;
  50. ota_trans_notify_cb_t cb;
  51. };
  52. static inline int ota_trans_get_type(struct ota_trans *trans)
  53. {
  54. __ASSERT_NO_MSG(trans);
  55. return trans->type;
  56. }
  57. static inline int ota_trans_ioctl(struct ota_trans *trans, int cmd,
  58. void* param)
  59. {
  60. __ASSERT_NO_MSG(trans);
  61. if (trans->api->ioctl) {
  62. return trans->api->ioctl(trans, cmd, param);
  63. }
  64. return 0;
  65. }
  66. static inline int ota_trans_read(struct ota_trans *trans, int offset,
  67. void *buf, int size)
  68. {
  69. __ASSERT_NO_MSG(trans);
  70. return trans->api->read(trans, offset, buf, size);
  71. }
  72. static inline int ota_trans_open(struct ota_trans *trans)
  73. {
  74. __ASSERT_NO_MSG(trans);
  75. return trans->api->open(trans);
  76. }
  77. static inline int ota_trans_close(struct ota_trans *trans)
  78. {
  79. __ASSERT_NO_MSG(trans);
  80. return trans->api->close(trans);
  81. }
  82. static inline void ota_trans_exit(struct ota_trans *trans)
  83. {
  84. __ASSERT_NO_MSG(trans);
  85. return trans->api->exit(trans);
  86. }
  87. static inline int ota_trans_init(struct ota_trans *trans, int type,
  88. struct ota_trans_api *api,
  89. ota_trans_notify_cb_t cb)
  90. {
  91. __ASSERT_NO_MSG(trans);
  92. trans->type = type;
  93. trans->api = api;
  94. trans->cb = cb;
  95. return 0;
  96. }
  97. #endif /* __OTA_TRANS_H__ */