11 #if defined(HAVE_ASSERT_H) && !defined(assert)
18 #ifdef HAVE_ARPA_INET_H
19 #include <arpa/inet.h>
32 MEMB(pdu_storage, _pdu, COAP_PDU_MAXCNT);
35 coap_pdu_resources_init() {
36 memb_init(&pdu_storage);
57 unsigned short id,
size_t size) {
102 memb_free(&pdu_storage, pdu);
108 const size_t HEADERLENGTH = len + 4;
110 if (!pdu || len > 8 || pdu->
max_size < HEADERLENGTH)
117 pdu->
length = HEADERLENGTH;
131 if (type < pdu->max_delta) {
132 warn(
"coap_add_option: options are not in correct order\n");
136 opt = (
unsigned char *)pdu->
hdr + pdu->
length;
143 warn(
"coap_add_option: cannot add option\n");
157 assert(pdu->
data == NULL);
163 warn(
"coap_add_data: cannot add: data too large for PDU\n");
164 assert(pdu->
data == NULL);
172 memcpy(pdu->
data, data, len);
191 return *data != NULL;
194 #ifndef SHORT_ERROR_RESPONSE
229 for (i = 0; coap_error[i].
code; ++i) {
230 if (coap_error[i].code == code)
231 return coap_error[i].
phrase;
247 assert(optp); assert(*optp);
252 assert(optsize <= *length);
269 debug(
"insufficient space to store parsed PDU\n");
274 debug(
"discarded invalid PDU\n");
278 pdu->
hdr->
type = (data[0] >> 4) & 0x03;
286 debug(
"coap_pdu_parse: empty message is not empty\n");
293 debug(
"coap_pdu_parse: invalid Token\n");
299 memcpy(&pdu->
hdr->
id, data + 2, 2);
315 debug(
"coap_pdu_parse: drop\n");
326 debug(
"coap_pdu_parse: message ending in payload start marker\n");
330 debug(
"set data to %p (pdu ends at %p)\n", (
unsigned char *)opt,
331 (
unsigned char *)pdu->
hdr + pdu->
length);
332 pdu->
data = (
unsigned char *)opt;