5 #define INFO(...) printf(__VA_ARGS__); printf("\r\n");
6 #define INFOX(...); printf(__VA_ARGS__);
7 #define ERR(...) printf(__VA_ARGS__); printf("\r\n");
10 #define DBG(...) fprintf(stderr,"%s:%d ",__FILE__,__LINE__); fprintf(stderr,__VA_ARGS__); fprintf(stderr,"\r\n");
11 #define DBGX(...) fprintf(stderr,__VA_ARGS__);
12 #define DBGLX(...) fprintf(stderr,"%s:%d ",__FILE__,__LINE__); fprintf(stderr,__VA_ARGS__);
13 #define DBG_PDU() printBin();
17 #define DBGLX(...) {};
21 #define COAP_HDR_SIZE 4
22 #define COAP_OPTION_HDR_BYTE 1
44 COAP_CONFIRMABLE=0x00,
45 COAP_NON_CONFIRMABLE=0x10,
46 COAP_ACKNOWLEDGEMENT=0x20,
62 COAP_BAD_REQUEST=0x80,
67 COAP_METHOD_NOT_ALLOWED,
69 COAP_PRECONDITION_FAILED=0x8C,
70 COAP_REQUEST_ENTITY_TOO_LARGE=0x8D,
71 COAP_UNSUPPORTED_CONTENT_FORMAT=0x8F,
72 COAP_INTERNAL_SERVER_ERROR=0xA0,
75 COAP_SERVICE_UNAVAILABLE,
77 COAP_PROXYING_NOT_SUPPORTED
82 COAP_OPTION_IF_MATCH=1,
83 COAP_OPTION_URI_HOST=3,
85 COAP_OPTION_IF_NONE_MATCH,
88 COAP_OPTION_LOCATION_PATH,
89 COAP_OPTION_URI_PATH=11,
90 COAP_OPTION_CONTENT_FORMAT,
91 COAP_OPTION_MAX_AGE=14,
92 COAP_OPTION_URI_QUERY,
93 COAP_OPTION_ACCEPT=17,
94 COAP_OPTION_LOCATION_QUERY=20,
95 COAP_OPTION_BLOCK2=23,
96 COAP_OPTION_BLOCK1=27,
98 COAP_OPTION_PROXY_URI=35,
99 COAP_OPTION_PROXY_SCHEME=39,
105 COAP_CONTENT_FORMAT_TEXT_PLAIN = 0,
106 COAP_CONTENT_FORMAT_APP_LINK = 40,
107 COAP_CONTENT_FORMAT_APP_XML,
108 COAP_CONTENT_FORMAT_APP_OCTET,
109 COAP_CONTENT_FORMAT_APP_EXI = 47,
110 COAP_CONTENT_FORMAT_APP_JSON = 50
115 uint16_t optionDelta;
116 uint16_t optionNumber;
117 uint16_t optionValueLength;
119 uint8_t *optionPointer;
120 uint8_t *optionValuePointer;
125 CoapPDU(uint8_t *pdu,
int pduLength);
126 CoapPDU(uint8_t *buffer,
int bufferLength,
int pduLength);
143 int setToken(uint8_t *token, uint8_t tokenLength);
146 void setCode(CoapPDU::Code code);
154 int addOption(uint16_t optionNumber, uint16_t optionLength, uint8_t *optionValue);
159 int setURI(
char *uri,
int urilen);
160 int getURI(
char *dst,
int dstlen,
int *outLen);
191 int _constructedFromBuffer;
194 uint8_t *_payloadPointer;
198 uint16_t _maxAddedOptionNumber;
201 void shiftPDUUp(
int shiftOffset,
int shiftAmount);
202 void shiftPDUDown(
int startLocation,
int shiftOffset,
int shiftAmount);
203 uint8_t codeToValue(CoapPDU::Code c);
206 int findInsertionPosition(uint16_t optionNumber, uint16_t *prevOptionNumber);
207 int computeExtraBytes(uint16_t n);
208 int insertOption(
int insertionPosition, uint16_t optionDelta, uint16_t optionValueLength, uint8_t *optionValue);
209 uint16_t getOptionDelta(uint8_t *option);
210 void setOptionDelta(
int optionPosition, uint16_t optionDelta);
211 uint16_t getOptionValueLength(uint8_t *option);