lightduer_ca.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. // Author: Su Hao (suhao@baidu.com)
  17. //
  18. // Desc: Provide the API for external applications.
  19. #ifndef BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_INCLUDE_BAIDU_CA_H
  20. #define BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_INCLUDE_BAIDU_CA_H
  21. #include "lightduer_types.h"
  22. #include "lightduer_coap.h"
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /*
  27. * Acquire the handler
  28. *
  29. * @Param soc_ctx, in socket context
  30. * @Return duer_handler, the global context handler
  31. */
  32. DUER_EXT duer_handler baidu_ca_acquire(duer_transevt_func soc_ctx);
  33. /*
  34. * Acquire the resources for response
  35. *
  36. * @Param hdlr, in, the handler will be operated
  37. * @Param list_res, in, resource list
  38. * @Param list_res_size, in resource list length
  39. * @Return duer_status_t, in, the operation result
  40. */
  41. DUER_EXT duer_status_t baidu_ca_add_resources(duer_handler hdlr,
  42. const duer_res_t list_res[],
  43. duer_size_t list_res_size);
  44. /*
  45. * Load the configuration infomation
  46. *
  47. * @Param hdlr, in, the handler will be operated
  48. * @Param data, in, the configuration data
  49. * @Param size, in, the data size
  50. * @Return duer_status_t, in, the operation result
  51. */
  52. DUER_EXT duer_status_t baidu_ca_load_configuration(duer_handler hdlr, const void *data, duer_size_t size);
  53. DUER_EXT duer_status_t baidu_ca_unload_configuration(duer_handler hdlr);
  54. /*
  55. * Start run the Baidu CA, prepare the environment.
  56. *
  57. * @Param hdlr, in, the handler will be operated
  58. * @Return duer_status_t, in, the operation result
  59. */
  60. DUER_EXT duer_status_t baidu_ca_start(duer_handler hdlr);
  61. /*
  62. *
  63. * Determine the CA is started.
  64. *
  65. * @Param hdlr, in, the handler will be operated
  66. * @Return duer_bool, DUER_TRUE if started, else return DUER_FALSE.
  67. */
  68. DUER_EXT duer_bool baidu_ca_is_started(duer_handler hdlr);
  69. /*
  70. *
  71. * Determine the CA is stopped.
  72. *
  73. * @Param hdlr, in, the handler will be operated
  74. * @Return duer_bool, DUER_TRUE if stopped, else return DUER_FALSE.
  75. */
  76. DUER_EXT duer_bool baidu_ca_is_stopped(duer_handler hdlr);
  77. /*
  78. * Set the Reporter report response callback.
  79. *
  80. * @Param hdlr, in, the handler will be operated
  81. * @Param f_response, in, the callback for notify user the report data response
  82. * @Return duer_status_t, in, the operation result
  83. */
  84. DUER_EXT duer_status_t baidu_ca_report_set_response_callback(duer_handler hdlr,
  85. duer_notify_f f_response,
  86. duer_context context);
  87. /*
  88. * Set the transmit data callback.
  89. *
  90. * @Param hdlr, in, the handler will be operated
  91. * @Param f_transmit, in, the callback for transmit encoded data.
  92. * @Return duer_status_t, in, the operation result
  93. */
  94. DUER_EXT duer_status_t baidu_ca_report_set_data_tx_callback(duer_handler hdlr, duer_transmit_f f_transmit);
  95. /*
  96. * Build the message body that will be reported.
  97. *
  98. * @Param hdlr, in, the handler will be operated
  99. * @Param data, in, the message report data
  100. * @Param size, in, the data size
  101. * @Param confirmable, in, the report data QoS
  102. * @Return duer_msg_t *, in, the generated message body,
  103. * it SHOULD be released by ${link baidu_ca_release_message}
  104. */
  105. DUER_EXT duer_msg_t* baidu_ca_build_report_message(duer_handler hdlr,
  106. duer_bool confirmable);
  107. /*
  108. * Build the message body that will be responsed to remote.
  109. *
  110. * @Param hdlr, in, the handler will be operated
  111. * @Param msg, in, the message that remote requested
  112. * @Param msg_code, out, the response message code
  113. * @Return duer_msg_t *, in, the generated message body,
  114. * it SHOULD be released by ${link baidu_ca_release_message}
  115. */
  116. DUER_EXT duer_msg_t* baidu_ca_build_response_message(duer_handler hdlr,
  117. const duer_msg_t* msg,
  118. duer_u8_t msg_code);
  119. /*
  120. * Build the seperate response to the request with the token.
  121. *
  122. * @Param hdlr, in, the handler will be operated
  123. * @Param ptoken, in, the token used in the message
  124. * @Param token_len, in, the length of the token
  125. * @Param msg_code, in, the response message code
  126. * @Param confirmable, in,
  127. * @Return duer_msg_t *, out, the generated message body,
  128. * it SHOULD be released by ${link baidu_ca_release_message}
  129. */
  130. DUER_EXT duer_msg_t* baidu_ca_build_seperate_response_message(duer_handler hdlr,
  131. const char *ptoken,
  132. duer_size_t token_len,
  133. int msg_code,
  134. duer_bool confirmable);
  135. /*
  136. * Release the message that generated by baidu_ca_build_XXXX_message.
  137. *
  138. * @Param hdlr, in, the handler will be operated
  139. * @Param msg, in, the message that remote requested
  140. */
  141. DUER_EXT void baidu_ca_release_message(duer_handler hdlr, duer_msg_t* msg);
  142. /*
  143. * Send the message
  144. *
  145. * @Param hdlr, in, the handler will be operated
  146. * @Param msg, in, the msg will be sent
  147. * @Param addr, in, the remote addr
  148. * @Return duer_status_t, in, the operation result
  149. */
  150. DUER_EXT duer_status_t baidu_ca_send_data(duer_handler hdlr,
  151. const duer_msg_t* msg,
  152. const duer_addr_t* addr);
  153. /*
  154. * Send the user data
  155. *
  156. * @Param hdlr, in, the handler will be operated
  157. * @Param data, in, the user data
  158. * @Param size, in, the data size
  159. * @Param addr, in, the remote addr
  160. * @Return duer_status_t, in, the operation result
  161. */
  162. DUER_EXT duer_status_t baidu_ca_send_data_directly(duer_handler hdlr,
  163. const void *data,
  164. duer_size_t szie,
  165. const duer_addr_t* addr);
  166. /*
  167. * When the message data has ready to be received
  168. *
  169. * @Param hdlr, in, the handler will be operated
  170. * @Param addr, in, the remote addr
  171. * @Return duer_status_t, in, the operation result
  172. */
  173. DUER_EXT duer_status_t baidu_ca_data_available(duer_handler hdlr,
  174. const duer_addr_t* addr);
  175. /*
  176. * Execute the cached CoAP data, such as blockwise, resending...
  177. *
  178. * @Param hdlr, in, the handler will be operated
  179. * @Return duer_status_t, in, the operation result
  180. */
  181. DUER_EXT duer_status_t baidu_ca_exec(duer_handler hdlr);
  182. /*
  183. * Stop the Baidu CA.
  184. *
  185. * @Param hdlr, in, the handler will be operated
  186. * @Return duer_status_t, in, the operation result
  187. */
  188. DUER_EXT duer_status_t baidu_ca_stop(duer_handler hdlr);
  189. /*
  190. * Release the handler
  191. *
  192. * @Param hdlr, in, the handler will be operated
  193. * @Return duer_status_t, in, the operation result
  194. */
  195. DUER_EXT duer_status_t baidu_ca_release(duer_handler hdlr);
  196. /*
  197. * Obtain the uuid
  198. *
  199. * @Param hdlr, in, the handler will be operated
  200. * @Return const char *, The UUID string
  201. */
  202. DUER_EXT const char *baidu_ca_get_uuid(duer_handler hdlr);
  203. /*
  204. * Obtain the rsa cacrt
  205. *
  206. * @Param hdlr, in, the handler will be operated
  207. * @Return const char *, The RSA CACRT string
  208. */
  209. DUER_EXT const char *baidu_ca_get_rsa_cacrt(duer_handler hdlr);
  210. /*
  211. * Obtain the bindToken
  212. *
  213. * @Param hdlr, in, the handler will be operated
  214. * @Return const char *, The bindToken string
  215. */
  216. DUER_EXT const char *baidu_ca_get_bind_token(duer_handler hdlr);
  217. #ifdef __cplusplus
  218. }
  219. #endif
  220. #endif // BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_INCLUDE_BAIDU_CA_H