1 /* 2 * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 */ 4 5 #ifndef __COAP_MESSAGE_H__ 6 #define __COAP_MESSAGE_H__ 7 #include "CoAPExport.h" 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif /* __cplusplus */ 12 13 typedef struct { 14 CoAPMsgHeader header; 15 unsigned char retrans_count; 16 unsigned char token[COAP_MSG_MAX_TOKEN_LEN]; 17 unsigned long long timeout; 18 unsigned short timeout_val; 19 unsigned int msglen; 20 CoAPSendMsgHandler handler; 21 NetworkAddr remote; 22 struct list_head sendlist; 23 void *user; 24 unsigned char *message; 25 int acked; 26 int keep; 27 } CoAPSendNode; 28 29 int CoAPStrOption_add(CoAPMessage *message, unsigned short optnum, 30 unsigned char *data, unsigned short datalen); 31 32 int CoAPStrOption_get(CoAPMessage *message, unsigned short optnum, 33 unsigned char *data, unsigned short *datalen); 34 35 int CoAPUintOption_add(CoAPMessage *message, unsigned short optnum, 36 unsigned int data); 37 38 int CoAPUintOption_get(CoAPMessage *message, unsigned short optnum, 39 unsigned int *data); 40 41 int CoAPOption_present(CoAPMessage *message, unsigned short option); 42 43 unsigned short CoAPMessageId_gen(CoAPContext *context); 44 45 int CoAPMessageId_set(CoAPMessage *message, unsigned short msgid); 46 47 int CoAPMessageType_set(CoAPMessage *message, unsigned char type); 48 49 int CoAPMessageCode_set(CoAPMessage *message, CoAPMessageCode code); 50 51 int CoAPMessageToken_set(CoAPMessage *message, unsigned char *token, 52 unsigned char tokenlen); 53 54 int CoAPMessageUserData_set(CoAPMessage *message, void *userdata); 55 56 int CoAPMessageKeep_Set(CoAPMessage *message, int keep); 57 58 int CoAPMessagePayload_set(CoAPMessage *message, unsigned char *payload, 59 unsigned short payloadlen); 60 61 int CoAPMessageHandler_set(CoAPMessage *message, CoAPSendMsgHandler handler); 62 63 int CoAPMessage_init(CoAPMessage *message); 64 65 int CoAPMessage_destory(CoAPMessage *message); 66 67 int CoAPMessage_send(CoAPContext *context, NetworkAddr *remote, 68 CoAPMessage *message); 69 70 int CoAPMessage_recv(CoAPContext *context, unsigned int timeout, int readcount); 71 72 int CoAPMessage_retransmit(CoAPContext *context); 73 74 int CoAPMessage_process(CoAPContext *context, unsigned int timeout); 75 76 int CoAPMessage_cycle(CoAPContext *context); 77 78 int CoAPMessage_cancel(CoAPContext *context, CoAPMessage *message); 79 80 #ifdef __cplusplus 81 } 82 #endif /* __cplusplus */ 83 84 #endif 85