1 /*
2  * Copyright (C) 2015-2018 Alibaba Group Holding Limited
3  */
4 
5 #ifndef __COAP_EXPORT_H__
6 #define __COAP_EXPORT_H__
7 
8 #include "../iotx_coap_internal.h"
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif /* __cplusplus */
13 
14 typedef struct {
15     unsigned char send_maxcount; /*list maximal count*/
16     unsigned char obs_maxcount;  /*observe maximal count*/
17     unsigned short port;         /* Local port */
18     char *group;                 /* Multicast address */
19     unsigned int waittime;
20     CoAPEventNotifier notifier;
21     void *appdata;
22     unsigned char res_maxcount;
23 } CoAPInitParam;
24 
25 typedef enum {
26     PATH_NORMAL,
27     PATH_FILTER,
28 } path_type_t;
29 
30 CoAPContext *CoAPContext_create(CoAPInitParam *param);
31 
32 void CoAPContext_free(CoAPContext *context);
33 
34 void *CoAPContextAppdata_get(CoAPContext *context);
35 
36 /* CoAP message options APIs*/
37 extern int CoAPStrOption_add(CoAPMessage *message, unsigned short optnum,
38                              unsigned char *data, unsigned short datalen);
39 
40 extern int CoAPStrOption_get(CoAPMessage *message, unsigned short optnum,
41                              unsigned char *data, unsigned short *datalen);
42 
43 extern int CoAPUintOption_add(CoAPMessage *message, unsigned short optnum,
44                               unsigned int data);
45 
46 extern int CoAPUintOption_get(CoAPMessage *message, unsigned short optnum,
47                               unsigned int *data);
48 
49 extern int CoAPOption_present(CoAPMessage *message, unsigned short option);
50 
51 /*CoAP Message APIs*/
52 extern unsigned short CoAPMessageId_gen(CoAPContext *context);
53 
54 extern int CoAPMessageId_set(CoAPMessage *message, unsigned short msgid);
55 
56 extern int CoAPMessageType_set(CoAPMessage *message, unsigned char type);
57 
58 extern int CoAPMessageCode_set(CoAPMessage *message, CoAPMessageCode code);
59 
60 extern int CoAPMessageCode_get(CoAPMessage *message, CoAPMessageCode *code);
61 
62 extern int CoAPMessageToken_set(CoAPMessage *message, unsigned char *token,
63                                 unsigned char tokenlen);
64 
65 extern int CoAPMessageUserData_set(CoAPMessage *message, void *userdata);
66 
67 extern int CoAPMessageKeep_Set(CoAPMessage *message, int keep);
68 
69 extern int CoAPMessagePayload_set(CoAPMessage *message, unsigned char *payload,
70                                   unsigned short payloadlen);
71 
72 extern int CoAPMessageHandler_set(CoAPMessage *message,
73                                   CoAPSendMsgHandler handler);
74 
75 extern int CoAPMessage_init(CoAPMessage *message);
76 
77 extern int CoAPMessage_destory(CoAPMessage *message);
78 
79 extern int CoAPMessage_send(CoAPContext *context, NetworkAddr *remote,
80                             CoAPMessage *message);
81 
82 extern int CoAPMessage_process(CoAPContext *context, unsigned int timeout);
83 
84 extern int CoAPMessage_retransmit(CoAPContext *context);
85 
86 extern int CoAPMessage_cycle(CoAPContext *context);
87 
88 extern int CoAPMessage_cancel(CoAPContext *context, CoAPMessage *message);
89 
90 extern int CoAPMessageId_cancel(CoAPContext *context, unsigned short msgid);
91 
92 extern void CoAPMessage_dump(NetworkAddr *remote, CoAPMessage *message);
93 /*CoAP Resource APIs*/
94 extern int CoAPResource_register(CoAPContext *context, const char *path,
95                                  unsigned short permission, unsigned int ctype,
96                                  unsigned int maxage,
97                                  CoAPRecvMsgHandler callback);
98 
99 /*CoAP observe APIs*/
100 extern int CoAPObsServer_add(CoAPContext *context, const char *path,
101                              NetworkAddr *remote, CoAPMessage *request);
102 
103 extern int CoAPObsServer_notify(CoAPContext *context, const char *path,
104                                 unsigned char *payload,
105                                 unsigned short payloadlen,
106                                 CoAPDataEncrypt handler);
107 
108 #ifdef __cplusplus
109 }
110 #endif /* __cplusplus */
111 
112 #endif
113