ql_api_websocket.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*============================================================================
  2. Copyright (c) 2020 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
  3. Quectel Wireless Solution Proprietary and Confidential.
  4. =============================================================================*/
  5. /*===========================================================================
  6. EDIT HISTORY FOR MODULE
  7. This section contains comments describing changes made to the module.
  8. Notice that changes are listed in reverse chronological order.
  9. WHEN WHO WHAT, WHERE, WHY
  10. ---------- ------------ ----------------------------------------------------
  11. =============================================================================*/
  12. #ifndef QL_WEBSOCKET_CLIENT_API_H
  13. #define QL_WEBSOCKET_CLIENT_API_H
  14. #include "ql_api_common.h"
  15. #define QL_WEBSOCKET_LOG_LEVEL QL_LOG_LEVEL_INFO
  16. #define QL_WEBSOCKET_LOG(msg, ...) QL_LOG_TAG(QL_WEBSOCKET_LOG_LEVEL, QL_LOG_TAG_WEBSOCKET, "ql_websocket", msg, ##__VA_ARGS__)
  17. #define QL_WEBSOCKET_LOG_PUSH(msg, ...) QL_LOG_PUSH("ql_websocket", msg, ##__VA_ARGS__)
  18. //---- config id & client id limitation ----
  19. #define QWS_CFG_ID_NUM 3
  20. #define QWS_CLIENT_ID_NUM QWS_CFG_ID_NUM
  21. #define QL_WS_DATA_TEXT_FMT 0
  22. #define QL_WS_DATA_HEX_FMT 1
  23. #define QWS_LWS_TX_PKT_SZ 2048
  24. #define QWS_LWS_RX_PKT_SZ 2048
  25. typedef enum
  26. {
  27. QWS_CFG_TYPE_CONN,
  28. QWS_CFG_TYPE_PING,
  29. QWS_CFG_TYPE_WRITE,
  30. QWS_CFG_TYPE_READ,
  31. QWS_CFG_TYPE_CLOSE,
  32. QWS_CFG_CONN_PDPCID,
  33. QWS_CFG_CONN_SSLCTXID,
  34. QWS_CFG_CONN_URL,
  35. QWS_CFG_CONN_SUBPROT_EN,
  36. QWS_CFG_CONN_SUBPROT,
  37. QWS_CFG_CONN_EXTENSION_EN,
  38. QWS_CFG_CONN_EXTENSION,
  39. QWS_CFG_CONN_METHOD,
  40. QWS_CFG_CONN_TIMEOUT,
  41. QWS_CFG_PING_INTERVAL,
  42. QWS_CFG_WRITE_BUFFERSZ,
  43. QWS_CFG_WRITE_TIMEOUT,
  44. QWS_CFG_WRITE_ECHO,
  45. QWS_CFG_READ_BUFFERSZ,
  46. QWS_CFG_READ_TIMEOUT,
  47. QWS_CFG_READ_MODE,
  48. QWS_CFG_CLOSE_WAITTIME,
  49. QWS_CFG_RECV_CB,
  50. QWS_CFG_REQHEAD_ADD,
  51. QWS_CFG_REQHEAD_REMOVE,
  52. QWS_CFG_WRITE_MAX
  53. } qws_cfg_e_;
  54. typedef enum
  55. {
  56. QWS_CLIENT_GET_ERRCODE,
  57. QWS_CLIENT_GET_CONNSTATE,
  58. QWS_CLIENT_GET_UNSENT_SIZE,
  59. QWS_CLIENT_RES_MAX
  60. } qws_client_e_;
  61. //---- qws errno ----
  62. typedef enum
  63. {
  64. QWS_NEGATIVE_ERROR=-1,
  65. QWS_OK=0,
  66. QWS_ERR_GENERIC,
  67. QWS_ERR_PROT_FAIL,
  68. QWS_ERR_INVAL_PARM,
  69. QWS_ERR_NO_MEM,
  70. QWS_ERR_TIMEDOUT,
  71. QWS_ERR_BUSY,
  72. QWS_ERR_NOT_INIT,
  73. QWS_ERR_NET_FAIL,
  74. QWS_ERR_ID_OCCUPIED,
  75. QWS_ERR_INVAL_URL,
  76. QWS_ERR_TASK_CREATE,
  77. QWS_ERR_NET_CLOSE,
  78. QWS_ERR_NET_DOWN,
  79. } qws_err_e;
  80. typedef enum
  81. {
  82. QWS_CFG_READ_MODE_BUFFER,
  83. QWS_CFG_READ_MODE_PUSH
  84. } qws_cfg_read_mode_e;
  85. //---- connect state ----
  86. typedef enum
  87. {
  88. QWS_CONN_STA_IDLE,
  89. QWS_CONN_STA_CONNECTING,
  90. QWS_CONN_STA_CONNECTED,
  91. QWS_CONN_STA_CLOSING,
  92. QWS_CONN_STA_CLOSED=QWS_CONN_STA_IDLE
  93. } qws_conn_sta_e;
  94. typedef enum
  95. {
  96. QWS_CB_TYPE_RECV,
  97. QWS_CB_TYPE_OPEN,
  98. QWS_CB_TYPE_CLOSE,
  99. QWS_CB_TYPE_MAX
  100. } qws_cb_e_;
  101. typedef enum
  102. {
  103. QWS_WRITE_PROT_TEXT = 0,
  104. QWS_WRITE_PROT_BIN = 1,
  105. QWS_WRITE_PROT_MAX
  106. } qws_write_prot_e;
  107. typedef struct
  108. {
  109. int type;
  110. char *data;
  111. int size;
  112. int virtual;
  113. } qws_parm_t;
  114. typedef struct
  115. {
  116. int client_id;
  117. int cfg_id;
  118. char *data;
  119. int user;
  120. } qws_open_t;
  121. typedef int (*ws_client_recv_cb_t)(int client_id, qws_parm_t *cb_t);
  122. /*****************************************************************
  123. * Function: ql_ws_cfg_set_opt
  124. *
  125. * Description: 通过opt_tag类型信息,配置websocket client上下文
  126. *
  127. * Parameters:
  128. * cfg_id [in] websocket client 配置索引.
  129. * opt_tag [in] websocket client 上下文中配置的参数处理类型
  130. *
  131. * Return:
  132. * 0 成功
  133. * other 错误码
  134. *
  135. *****************************************************************/
  136. qws_err_e ql_ws_cfg_set_opt(uint8 cfg_id, int opt_tag,...);
  137. /*****************************************************************
  138. * Function: ql_ws_cfg_get_opt
  139. *
  140. * Description: 通过opt_tag类型信息,读取 websocket client 配置参数
  141. *
  142. * Parameters:
  143. * cfg_id [in] websocket client 配置索引.
  144. * opt_tag [in] websocket client 上下文中配置的参数处理类型
  145. *
  146. * Return:
  147. * 0 成功
  148. * other 错误码
  149. *
  150. *****************************************************************/
  151. qws_err_e ql_ws_cfg_get_opt(uint8 cfg_id, int opt_tag,...);
  152. /*****************************************************************
  153. * Function: ql_ws_open_proc
  154. *
  155. * Description: websocket client 启动 qws_open_t 配置信息
  156. *
  157. * Parameters:
  158. * client_id [in] websocket client 索引.
  159. * cfg_id [in] websocket client 配置索引.
  160. * data/user [in] 扩展保留信息.
  161. *
  162. * Return:
  163. * 0 成功
  164. * other 错误码
  165. *
  166. *****************************************************************/
  167. int ql_ws_open_proc(qws_open_t* open_t);
  168. /*****************************************************************
  169. * Function: ql_ws_write_proc
  170. *
  171. * Description: websocket client 发送数据
  172. *
  173. * Parameters:
  174. * client_id [in] websocket client 索引.
  175. * qws_parm_t [in] websocket client 发送数据结构.
  176. * type [in] 数据类型 QWS_WRITE_PROT_TEXT/QWS_WRITE_PROT_BIN
  177. * data [in] 要发送的数据
  178. * size [in] 要发送数据的长度
  179. *
  180. * Return:
  181. * 0 成功
  182. * other 错误码
  183. *
  184. *****************************************************************/
  185. int ql_ws_write_proc(int client_id, qws_parm_t *parm_t);
  186. /*****************************************************************
  187. * Function: ql_ws_close_proc
  188. *
  189. * Description: websocket client 关闭退出
  190. *
  191. * Parameters:
  192. * client_id [in] websocket client 索引.
  193. *
  194. * Return:
  195. * 0 成功
  196. * other 错误码
  197. *
  198. *****************************************************************/
  199. int ql_ws_close_proc(int client_id);
  200. /*****************************************************************
  201. * Function: ql_ws_client_get_opt
  202. *
  203. * Description: 通过opt_tag类型信息,读取 websocket client 参数
  204. *
  205. * Parameters:
  206. * client_id [in] websocket client 索引.
  207. * opt_tag [in] websocket client 上下文中的数据类型 qws_client_e_
  208. *
  209. * Return:
  210. * 0 成功
  211. * other 错误码
  212. *
  213. *****************************************************************/
  214. qws_err_e ql_ws_client_get_opt(uint8 client_id, int opt_tag,...);
  215. #endif /*QL_WEBSOCKET_CLIENT_API_H*/
  216. ///
  217. ///