Link Kit C-SDK  4.1.0
aiot_coap_api.h
浏览该文件的文档.
1 
23 #ifndef __AIOT_COAP_API_H__
24 #define __AIOT_COAP_API_H__
25 
26 #if defined(__cplusplus)
27 extern "C" {
28 #endif
29 
30 #include <stdint.h>
31 
35 #define STATE_COAP_BASE (-0x0800)
36 
41 #define STATE_COAP_LOG_HEXDUMP (-0x0801)
42 
47 #define STATE_COAP_HEADER_TYPE_ERROR (-0x0802)
48 
53 #define STATE_COAP_HEADER_CODE_ERROR (-0x0802)
54 
59 #define STATE_COAP_MSG_LEN_ERROR (-0x0803)
60 
65 #define STATE_COAP_MSG_TOKEN_LEN_TOO_SHORT (-0x0804)
66 
71 #define STATE_COAP_RX_OPTION_CNT_EXCEED_LIMIT (-0x0805)
72 
77 #define STATE_COAP_OPT_DELTA_THIRTEEN_OPT_LEN_ERROR (-0x0806)
78 
83 #define STATE_COAP_OPTION_END_NOT_FOUND (-0x0807)
84 
89 #define STATE_COAP_TX_URI_OPTION_CNT_EXCEED_LIMIT (-0x0808)
90 
95 #define STATE_COAP_MALLOC_MSG_FAILED (-0x0809)
96 
101 #define STATE_COAP_MALLOC_MSG_BUFFER_FAILED (-0x080A)
102 
107 #define STATE_COAP_REQUEST_IS_NULL (-0x080B)
108 
113 #define STATE_COAP_OPT_DELTA_FOURTEEN_OPT_LEN_ERROR (-0x080C)
114 
119 #define STATE_COAP_EMPTY_MSG_PARAM_ERROR (-0x080D)
120 
125 #define STATE_COAP_EMPTY_MSG_MALLOC_FAILED (-0x080E)
126 
131 #define STATE_COAP_OPTION_NOT_IN_ORDER (-0x080F)
132 
137 #define STATE_COAP_HEADER_FORMAT_ERROR (-0x0810)
138 
143 #define STATE_COAP_OPTION_BUFFER_TOO_SHORT (-0x081A)
144 
149 #define STATE_COAP_SEND_MESSAGE_IS_NULL (-0x081B)
150 
155 #define STATE_COAP_HEADER_BUFFER_IS_TOO_SHORT (-0x081C)
156 
161 #define STATE_COAP_OPT_LEN_THIRTEEN_OPT_LEN_ERROR (-0x081D)
162 
167 #define STATE_COAP_CREATE_PSK_FAILED (-0x081E)
168 
175 #define STATE_COAP_SET_NWK_PARMS_FAILED (-0x081F)
176 
181 #define STATE_COAP_SEND_HANDLE_IS_NULL (-0x0820)
182 
187 #define STATE_COAP_SEND_TOPIC_IS_NULL (-0x0821)
188 
193 #define STATE_COAP_SEND_REQUEST_IS_NULL (-0x0822)
194 
199 #define STATE_COAP_SEND_PAYLOAD_IS_NULL (-0x0823)
200 
205 #define STATE_COAP_SET_PSK_FAILED (-0x0824)
206 
211 #define STATE_COAP_NWK_ESTABLISH_FAILED (-0x0825)
212 
217 #define STATE_COAP_RECV_HANDLE_IS_NULL (-0x0826)
218 
223 #define STATE_COAP_AUTH_HANDLE_IS_NULL (-0x0827)
224 
229 #define STATE_COAP_AUTH_DEVICE_INFO_MISSING (-0x0828)
230 
235 #define STATE_COAP_SIGN_SRC_MALLOC_FAILED (-0x0829)
236 
241 #define STATE_COAP_TX_TOTAL_OPTION_CNT_EXCEED_LIMIT (-0x082A)
242 
247 #define STATE_COAP_RECV_WITHOUT_AUTHORIZATION (-0x082B)
248 
253 #define STATE_COAP_AUTH_TIMEOUT (-0x082C)
254 
259 #define STATE_COAP_AUTH_RSP_TOKEN_IS_NULL (-0x082D)
260 
265 #define STATE_COAP_AUTH_DEBUG (-0x082E)
266 
271 #define STATE_COAP_AUTH_TOKEN_MALLOC_FAILED (-0x082F)
272 
280 #define STATE_COAP_SEND_INVALID_MSG_TYPE (-0x0830)
281 
286 #define STATE_COAP_NWK_HANDLE_IS_NULL (-0x0831)
287 
292 #define AIOT_COAP_OPT_PARAMS_INVALID (-0x0832)
293 
298 #define STATE_COAP_INVALID_OPTION (-0x0833)
299 
304 #define STATE_COAP_UNSUPPORTED_CONTENT_FORMAT (-0x0834)
305 
310 #define STATE_COAP_SEND_WITHOUT_AUTHORIZATION (-0x0835)
311 
316 #define STATE_COAP_OPT_LEN_FOURTEEN_OPT_LEN_ERROR (-0x0836)
317 
322 #define STATE_COAP_PAYLOAD_BUFFER_IS_TOO_SHORT (-0x0837)
323 
328 #define STATE_COAP_OPTION_LEN_ERROR (-0x0838)
329 
334 #define STATE_COAP_LOG_AUTH_TOKEN (-0x0839)
335 
340 #define STATE_COAP_LOG_CONTENT (-0x083A)
341 
346 #define STATE_COAP_INPUT_OUT_RANGE (-0x083B)
347 
352 #define STATE_COAP_DYNREG_SECRET_TOO_LONG (-0x0840)
353 
358 #define STATE_COAP_DYNREG_HANDLE_IS_NULL (-0x0841)
359 
364 #define STATE_COAP_DYNREG_DEVICE_INFO_MISSING (-0x0842)
365 
370 #define STATE_COAP_DYNREG_TIMEOUT (-0x0843)
371 
376 #define STATE_COAP_AUTH_FAILED (-0x0844)
377 
378 
379 
387 typedef enum {
390 
391 typedef struct {
392 
397  aiot_coap_recv_type_t type;
398 
402  struct {
403  uint8_t *payload;
404  uint32_t payload_len;
405  uint8_t rsp_code;
406  uint32_t msg_token;
407  uint16_t msg_id;
408  } data;
410 
420 typedef void (*aiot_coap_recv_handler_t)(void *handle,
421  aiot_coap_recv_t *packet,
422  void *userdata);
423 
427 typedef enum {
428 
433 
439 
440 typedef struct {
441 
445  aiot_coap_event_type_t type;
447 
456 typedef void (*aiot_coap_event_handler_t)(void *handle,
457  aiot_coap_event_t *event,
458  void *userdata);
459 
460 
479 typedef enum {
480 
496 
509 
518 
527 
536 
550 
558 
567 
577 
590 
599 
610 
621 
635 typedef enum {
645 
661 typedef enum {
662 
668 
674 
689 
696 typedef struct {
697 
702  uint8_t *payload;
707  uint32_t payload_len;
708 
717 
723 
728  uint32_t *msg_token;
730 
731 
740 void *aiot_coap_init(void);
741 
776 int32_t aiot_coap_setopt(void *handle, aiot_coap_option_t option, void *data);
777 
795 int32_t aiot_coap_send(void *handle, const char *topic, aiot_coap_request_t *message);
796 
808 int32_t aiot_coap_recv(void *handle);
809 
819 int32_t aiot_coap_deinit(void **handle);
820 
835 int32_t aiot_coap_auth(void *handle);
836 
854 int32_t aiot_coap_dynreg(void *handle, const char *product_secret, char *out_secret, uint32_t out_secret_maxlen);
855 
856 
868 int32_t aiot_coap_request_message(void *handle, int32_t counter);
869 
870 #if defined(__cplusplus)
871 }
872 #endif
873 
874 #endif /* __AIOT_COAP_API_H__ */
875 
aiot_coap_msg_type_t msg_type
aiot_coap_msg_type_t 中所定义的消息类型
Definition: aiot_coap_api.h:716
Definition: aiot_coap_api.h:391
aiot_coap_msg_type_t
aiot_coap_send 函数的aiot_coap_request_t参数中的msg_type字段.
Definition: aiot_coap_api.h:661
uint8_t * payload
用户要上传的数据, 其格式要和字段content_format一致.
Definition: aiot_coap_api.h:702
uint32_t * msg_token
用户传入一个指针. 在coap模块发送该请求的时候, 会对该请求生成一个独一无二的token 该指针用以存这个token...
Definition: aiot_coap_api.h:728
Definition: aiot_coap_api.h:687
void(* aiot_coap_event_handler_t)(void *handle, aiot_coap_event_t *event, void *userdata)
COAP事件回调函数
Definition: aiot_coap_api.h:456
int32_t aiot_coap_dynreg(void *handle, const char *product_secret, char *out_secret, uint32_t out_secret_maxlen)
设备动态注册,返回设备密钥
Definition: aiot_coap_api.c:1291
当COAP实例所用的auth token过期(当前有效期为7天)时, 触发此事件
Definition: aiot_coap_api.h:437
Definition: aiot_coap_api.h:619
应用层数据PAYLOAD使用AES加密啊
Definition: aiot_coap_api.h:618
设备的device secret, 可从阿里云物联网平台控制台获取
Definition: aiot_coap_api.h:535
Definition: aiot_coap_api.h:641
aiot_coap_event_type_t
COAP内部事件类型
Definition: aiot_coap_api.h:427
confirmable消息类型
Definition: aiot_coap_api.h:667
COAP连云时, 获取auth_token的超时时间
Definition: aiot_coap_api.h:557
Definition: aiot_coap_api.h:388
not confirmable消息类型
Definition: aiot_coap_api.h:673
Definition: aiot_coap_api.h:638
int32_t aiot_coap_deinit(void **handle)
释放COAP实例句柄的资源
Definition: aiot_coap_api.c:1130
int32_t aiot_coap_send(void *handle, const char *topic, aiot_coap_request_t *message)
发送COAP报文
Definition: aiot_coap_api.c:996
aiot_coap_send 函数的aiot_coap_request_t参数
Definition: aiot_coap_api.h:696
Definition: aiot_coap_api.h:639
reset消息类型
Definition: aiot_coap_api.h:685
uint8_t * payload
Definition: aiot_coap_api.h:403
Definition: aiot_coap_api.h:642
uint32_t payload_len
用户要上传的数据, 其格式要和字段content_format一致.
Definition: aiot_coap_api.h:707
int32_t aiot_coap_request_message(void *handle, int32_t counter)
设备主动请求下拉消息
Definition: aiot_coap_api.c:1170
ack消息类型
Definition: aiot_coap_api.h:679
aiot_coap_recv_type_t type
COAP报文类型, 更多信息请参考aiot_coap_recv_type_t.
Definition: aiot_coap_api.h:397
int32_t aiot_coap_setopt(void *handle, aiot_coap_option_t option, void *data)
设置coap参数
Definition: aiot_coap_api.c:788
aiot_coap_event_type_t type
COAP事件类型, 更多信息请参考aiot_coap_event_type_t.
Definition: aiot_coap_api.h:445
aiot_coap_recv_type_t
COAP报文类型
Definition: aiot_coap_api.h:387
设备的product key, 可从阿里云物联网平台控制台获取
Definition: aiot_coap_api.h:517
COAP建联时, 网络使用的安全凭据
Definition: aiot_coap_api.h:549
COAP接收数据时, 在协议栈花费的最长时间
Definition: aiot_coap_api.h:566
int32_t aiot_coap_auth(void *handle)
让coap模块与服务器通信, 并且获取auth token
Definition: aiot_coap_api.c:930
void * aiot_coap_init(void)
初始化coap实例并设置默认参数
Definition: aiot_coap_api.c:749
uint32_t msg_token
Definition: aiot_coap_api.h:406
COAP客户端内部发生的事件会从此回调函数进行通知, 如获取到token等
Definition: aiot_coap_api.h:598
从COAP服务器收取的数据从此回调函数通知用户
Definition: aiot_coap_api.h:589
aiot_coap_option_t
aiot_coap_setopt 函数的option参数. 对于下文每一个选项中的数据类型, 指的是aiot_coap_setopt 中的data参...
Definition: aiot_coap_api.h:479
Definition: aiot_coap_api.h:640
Definition: aiot_coap_api.h:643
当COAP实例从云端获取到连云需要的auth_token时, 触发此事件
Definition: aiot_coap_api.h:432
Definition: aiot_coap_api.h:637
COAP发送数据时, 在协议栈花费的最长时间
Definition: aiot_coap_api.h:576
Definition: aiot_coap_api.h:636
int32_t aiot_coap_recv(void *handle)
从网络收取COAP报文
Definition: aiot_coap_api.c:1116
uint8_t rsp_code
Definition: aiot_coap_api.h:405
aiot_coap_content_format_t content_format
aiot_coap_content_format_t 中所定义的payload的格式
Definition: aiot_coap_api.h:722
COAP 服务器的端口号
Definition: aiot_coap_api.h:508
COAP 服务器的域名地址或者ip地址
Definition: aiot_coap_api.h:495
void(* aiot_coap_recv_handler_t)(void *handle, aiot_coap_recv_t *packet, void *userdata)
COAP报文接收回调函数原型
Definition: aiot_coap_api.h:420
aiot_coap_content_format_t
aiot_coap_send 函数的aiot_coap_request_t参数中的content_format字段.
Definition: aiot_coap_api.h:635
设备的device name, 可从阿里云物联网平台控制台获取
Definition: aiot_coap_api.h:526
用户需要SDK暂存的上下文
Definition: aiot_coap_api.h:609
uint16_t msg_id
Definition: aiot_coap_api.h:407
uint32_t payload_len
Definition: aiot_coap_api.h:404
Definition: aiot_coap_api.h:440