1 /*
2  * Copyright (C) 2015-2018 Alibaba Group Holding Limited
3  */
4 
5 #include "CoAPExport.h"
6 
7 #ifndef __COAP_ALCS_H__
8 #define __COAP_ALCS_H__
9 
10 #define OPTSESESSION      62
11 #define ALCSPORT          5683
12 #define ALCSPORT_SECURE   5684
13 #define MULTICAST_ADDRESS "224.0.1.187"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif /* __cplusplus */
18 
19 #ifndef bool
20 #define bool char
21 #endif
22 
23 typedef struct {
24     NetworkAddr addr;
25     char *path;
26     char *query;
27 } ResourceAddr;
28 
29 /* 会自动生成msgid & token */
30 void alcs_msg_init(CoAPContext *ctx, CoAPMessage *message, int code,
31                    unsigned char type, int keep, CoAPLenString *payload,
32                    void *userdata);
33 void alcs_msg_deinit(CoAPMessage *message);
34 int alcs_msg_setAddr(CoAPMessage *message, const char *path, const char *query);
35 
36 /* observe: 0 register */
37 /* observer:1 deregister */
38 /* observer:other 没意义 */
39 int alcs_sendmsg(CoAPContext *ctx, NetworkAddr *addr, CoAPMessage *message,
40                  char observe, CoAPSendMsgHandler handler);
41 
42 /* msgid & token从接收到CoAPMessage获取, 若发送的是事件通知,msgid设置为0 */
43 /* observe: 0: accept register */
44 /* observe: other: 没意义   */
45 int alcs_sendrsp(CoAPContext *ctx, NetworkAddr *addr, CoAPMessage *message,
46                  char observe, unsigned short msgid, CoAPLenString *token);
47 
48 void alcs_start_loop(CoAPContext *ctx, int newThread);
49 void alcs_stop_loop(CoAPContext *ctx);
50 
51 /* 服务端接口
52  *
53  */
54 /* observe */
55 int alcs_observe_notify(CoAPContext *context, const char *path,
56                         CoAPLenString *payload);
57 
58 /* resource */
59 int alcs_resource_register(CoAPContext *context, const char *pk, const char *dn,
60                            const char *path, unsigned short permission,
61                            unsigned int ctype, unsigned int maxage,
62                            char needAuth, CoAPRecvMsgHandler callback);
63 
64 int alcs_resource_need_auth(CoAPContext *context, const char *path);
65 
66 /* init */
67 void alcs_init();
68 void alcs_deinit();
69 
70 #ifdef SUPPORT_MULTI_DEVICES
71 CoAPContext *alcs_context_create(CoAPInitParam *param);
72 void alcs_context_free(CoAPContext *ctx);
73 #else
74 CoAPContext *alcs_context_init(CoAPInitParam *param);
75 void alcs_context_deinit();
76 CoAPContext *alcs_get_context();
77 #endif
78 
79 /* option  */
80 extern int CoAPUintOption_add(CoAPMessage *message, unsigned short optnum,
81                               unsigned int data);
82 extern int CoAPUintOption_get(CoAPMessage *message, unsigned short optnum,
83                               unsigned int *data);
84 extern int CoAPStrOption_add(CoAPMessage *message, unsigned short optnum,
85                              unsigned char *data, unsigned short datalen);
86 extern int CoAPMessage_cancel(CoAPContext *context, CoAPMessage *message);
87 
88 uint32_t getToken();
89 
90 /*  */
91 #ifdef __cplusplus
92 }
93 #endif /* __cplusplus */
94 
95 #endif
96