1 /* pdu.c -- CoAP message structure
3 * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
5 * This file is part of the CoAP library libcoap. Please see
6 * README for terms of use.
11 #if defined(HAVE_ASSERT_H) && !defined(assert)
18 #ifdef HAVE_ARPA_INET_H
19 #include <arpa/inet.h>
35 typedef unsigned char _pdu[sizeof(coap_pdu_t) + COAP_MAX_PDU_SIZE];
37 MEMB(pdu_storage, _pdu, COAP_PDU_MAXCNT);
41 coap_pdu_resources_init()
43 memb_init(&pdu_storage);
45 #else /* WITH_CONTIKI */
47 #endif /* WITH_CONTIKI */
49 void coap_pdu_clear(coap_pdu_t *pdu, size_t size, coap_transport_type transport, unsigned int length)
53 memset(pdu, 0, sizeof(coap_pdu_t) + size);
55 pdu->hdr = (coap_hdr_t *) ((unsigned char *) pdu + sizeof(coap_pdu_t));
57 if (coap_udp == transport)
59 pdu->hdr->coap_hdr_udp_t.version = COAP_DEFAULT_VERSION;
60 /* data is NULL unless explicitly set by coap_add_data() */
61 pdu->length = sizeof(pdu->hdr->coap_hdr_udp_t);
66 /* data is NULL unless explicitly set by coap_add_data() */
74 coap_pdu_from_pbuf(struct pbuf *pbuf)
76 LWIP_ASSERT("Can only deal with contiguous PBUFs", pbuf->tot_len == pbuf->len);
77 LWIP_ASSERT("coap_read needs to receive an exclusive copy of the incoming pbuf", pbuf->ref == 1);
79 void *data = pbuf->payload;
82 u8_t header_error = pbuf_header(pbuf, sizeof(coap_pdu_t));
83 LWIP_ASSERT("CoAP PDU header does not fit in existing header space", header_error == 0);
85 result = (coap_pdu_t *)pbuf->payload;
87 memset(result, 0, sizeof(coap_pdu_t));
89 result->max_size = pbuf->tot_len - sizeof(coap_pdu_t);
90 result->length = pbuf->tot_len - sizeof(coap_pdu_t);
99 coap_pdu_init(unsigned char type, unsigned char code, unsigned short id,
100 size_t size, coap_transport_type transport)
107 unsigned int length = 0;
111 length = sizeof(pdu->hdr->coap_hdr_udp_t);
115 length = COAP_TCP_HEADER_NO_FIELD;
118 length = COAP_TCP_HEADER_8_BIT;
121 length = COAP_TCP_HEADER_16_BIT;
124 length = COAP_TCP_HEADER_32_BIT;
128 debug("it has wrong type\n");
132 assert(size <= COAP_MAX_PDU_SIZE);
133 /* Size must be large enough to fit the header. */
134 if (size < length || size > COAP_MAX_PDU_SIZE)
138 /* size must be large enough for hdr */
139 #if defined(WITH_POSIX) || defined(WITH_ARDUINO)
140 pdu = (coap_pdu_t *) coap_malloc(sizeof(coap_pdu_t) + size);
143 pdu = (coap_pdu_t *)memb_alloc(&pdu_storage);
146 p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM);
149 u8_t header_error = pbuf_header(p, sizeof(coap_pdu_t));
150 /* we could catch that case and allocate larger memory in advance, but then
151 * again, we'd run into greater trouble with incoming packages anyway */
152 LWIP_ASSERT("CoAP PDU header does not fit in transport header", header_error == 0);
162 coap_pdu_clear(pdu, size, transport, length);
167 pdu->hdr->coap_hdr_udp_t.id = id;
168 pdu->hdr->coap_hdr_udp_t.type = type;
169 pdu->hdr->coap_hdr_udp_t.code = code;
173 pdu->hdr->coap_hdr_tcp_t.header_data[0] = 0;
174 pdu->hdr->coap_hdr_tcp_t.header_data[1] = code;
177 pdu->hdr->coap_hdr_tcp_8bit_t.header_data[0] = COAP_TCP_LENGTH_FIELD_NUM_8_BIT << 4;
178 pdu->hdr->coap_hdr_tcp_8bit_t.header_data[2] = code;
181 pdu->hdr->coap_hdr_tcp_16bit_t.header_data[0] = COAP_TCP_LENGTH_FIELD_NUM_16_BIT << 4;
182 pdu->hdr->coap_hdr_tcp_16bit_t.header_data[3] = code;
185 pdu->hdr->coap_hdr_tcp_32bit_t.header_data[0] = COAP_TCP_LENGTH_FIELD_NUM_32_BIT << 4;
186 pdu->hdr->coap_hdr_tcp_32bit_t.header_data[5] = code;
190 debug("it has wrong type\n");
201 coap_new_pdu(coap_transport_type transport, unsigned int size)
206 pdu = coap_pdu_init(0, 0,
207 ntohs(COAP_INVALID_TID),
214 #else /* WITH_CONTIKI */
215 pdu = coap_pdu_init(0, 0, uip_ntohs(COAP_INVALID_TID),
222 #endif /* WITH_CONTIKI */
226 coap_log(LOG_CRIT, "coap_new_pdu: cannot allocate memory for new PDU\n");
231 void coap_delete_pdu(coap_pdu_t *pdu)
233 #if defined(WITH_POSIX) || defined(WITH_ARDUINO)
237 if (pdu != NULL) /* accepting double free as the other implementation accept that too */
238 pbuf_free(pdu->pbuf);
241 memb_free(&pdu_storage, pdu);
246 coap_transport_type coap_get_tcp_header_type_from_size(unsigned int size)
248 if (COAP_TCP_LENGTH_LIMIT_8_BIT < size && COAP_TCP_LENGTH_LIMIT_16_BIT >= size)
250 return coap_tcp_8bit;
252 else if (COAP_TCP_LENGTH_LIMIT_16_BIT < size && COAP_TCP_LENGTH_LIMIT_32_BIT >= size)
254 return coap_tcp_16bit;
256 else if (COAP_TCP_LENGTH_LIMIT_32_BIT < size)
258 return coap_tcp_32bit;
266 coap_transport_type coap_get_tcp_header_type_from_initbyte(unsigned int length)
268 coap_transport_type type;
271 case COAP_TCP_LENGTH_FIELD_NUM_8_BIT:
272 type = coap_tcp_8bit;
274 case COAP_TCP_LENGTH_FIELD_NUM_16_BIT:
275 type = coap_tcp_16bit;
277 case COAP_TCP_LENGTH_FIELD_NUM_32_BIT:
278 type = coap_tcp_32bit;
286 void coap_add_length(const coap_pdu_t *pdu, coap_transport_type transport, unsigned int length)
293 pdu->hdr->coap_hdr_tcp_t.header_data[0] = length << 4;
296 if (length > COAP_TCP_LENGTH_FIELD_8_BIT)
298 pdu->hdr->coap_hdr_tcp_8bit_t.header_data[1] =
299 length - COAP_TCP_LENGTH_FIELD_8_BIT;
303 if (length > COAP_TCP_LENGTH_FIELD_16_BIT)
305 unsigned int total_length = length - COAP_TCP_LENGTH_FIELD_16_BIT;
306 pdu->hdr->coap_hdr_tcp_16bit_t.header_data[1] = (total_length >> 8) & 0x0000ff;
307 pdu->hdr->coap_hdr_tcp_16bit_t.header_data[2] = total_length & 0x000000ff;
311 if (length > COAP_TCP_LENGTH_FIELD_32_BIT)
313 unsigned int total_length = length - COAP_TCP_LENGTH_FIELD_32_BIT;
314 pdu->hdr->coap_hdr_tcp_32bit_t.header_data[1] = total_length >> 24;
315 pdu->hdr->coap_hdr_tcp_32bit_t.header_data[2] = (total_length >> 16) & 0x00ff;
316 pdu->hdr->coap_hdr_tcp_32bit_t.header_data[3] = (total_length >> 8) & 0x0000ff;
317 pdu->hdr->coap_hdr_tcp_32bit_t.header_data[4] = total_length & 0x000000ff;
321 debug("it has wrong type\n");
325 unsigned int coap_get_length_from_header(const unsigned char *header, coap_transport_type transport)
329 unsigned int length = 0;
330 unsigned int length_field_data = 0;
334 length = header[1] + COAP_TCP_LENGTH_FIELD_8_BIT;
337 length_field_data = (header[1] << 8 | header[2]);
338 length = length_field_data + COAP_TCP_LENGTH_FIELD_16_BIT;
341 length_field_data = header[1] << 24 | header[2] << 16 | header[3] << 8 | header[4];
342 length = length_field_data + COAP_TCP_LENGTH_FIELD_32_BIT;
345 debug("it has wrong type\n");
351 unsigned int coap_get_length(const coap_pdu_t *pdu, coap_transport_type transport)
355 unsigned int length = 0;
356 unsigned int length_field_data = 0;
360 length = pdu->hdr->coap_hdr_tcp_t.header_data[0] >> 4;
363 length = pdu->hdr->coap_hdr_tcp_8bit_t.header_data[1] + COAP_TCP_LENGTH_FIELD_8_BIT;
367 pdu->hdr->coap_hdr_tcp_16bit_t.header_data[1] << 8 |
368 pdu->hdr->coap_hdr_tcp_16bit_t.header_data[2];
369 length = length_field_data + COAP_TCP_LENGTH_FIELD_16_BIT;
373 pdu->hdr->coap_hdr_tcp_32bit_t.header_data[1] << 24 |
374 pdu->hdr->coap_hdr_tcp_32bit_t.header_data[2] << 16 |
375 pdu->hdr->coap_hdr_tcp_32bit_t.header_data[3] << 8 |
376 pdu->hdr->coap_hdr_tcp_32bit_t.header_data[4];
377 length = length_field_data + COAP_TCP_LENGTH_FIELD_32_BIT;
380 debug("it has wrong type\n");
386 unsigned int coap_get_tcp_header_length(unsigned char *data)
390 unsigned int tokenLength = data[0] & 0x0f;
391 coap_transport_type transport =
392 coap_get_tcp_header_type_from_initbyte(data[0] >> 4);
393 unsigned int length = 0;
395 length = coap_get_tcp_header_length_for_transport(transport) + tokenLength;
399 unsigned int coap_get_tcp_header_length_for_transport(coap_transport_type transport)
401 unsigned int length = 0;
405 length = COAP_TCP_HEADER_NO_FIELD;
408 length = COAP_TCP_HEADER_8_BIT;
411 length = COAP_TCP_HEADER_16_BIT;
414 length = COAP_TCP_HEADER_32_BIT;
417 debug("it has wrong type\n");
423 size_t coap_get_opt_header_length(unsigned short key, size_t length)
425 size_t headerLength = 0;
427 unsigned short optDeltaLength = 0;
428 if (COAP_OPTION_FIELD_8_BIT >= key)
432 else if (COAP_OPTION_FIELD_8_BIT < key && COAP_OPTION_FIELD_16_BIT >= key)
436 else if (COAP_OPTION_FIELD_16_BIT < key && COAP_OPTION_FIELD_32_BIT >= key)
442 printf("Error : Reserved for the Payload marker for Delta");
446 size_t optLength = 0;
447 if (COAP_OPTION_FIELD_8_BIT >= length)
451 else if (COAP_OPTION_FIELD_8_BIT < length && COAP_OPTION_FIELD_16_BIT >= length)
455 else if (COAP_OPTION_FIELD_16_BIT < length && COAP_OPTION_FIELD_32_BIT >= length)
461 printf("Error : Reserved for the Payload marker for length");
465 headerLength = length + optDeltaLength + optLength + 1;
472 void coap_add_code(const coap_pdu_t *pdu, coap_transport_type transport, unsigned int code)
479 pdu->hdr->coap_hdr_udp_t.code = COAP_RESPONSE_CODE(code);
483 pdu->hdr->coap_hdr_tcp_t.header_data[1] = COAP_RESPONSE_CODE(code);
486 pdu->hdr->coap_hdr_tcp_8bit_t.header_data[2] = COAP_RESPONSE_CODE(code);
489 pdu->hdr->coap_hdr_tcp_16bit_t.header_data[3] = COAP_RESPONSE_CODE(code);
492 pdu->hdr->coap_hdr_tcp_32bit_t.header_data[5] = COAP_RESPONSE_CODE(code);
496 debug("it has wrong type\n");
500 unsigned int coap_get_code(const coap_pdu_t *pdu, coap_transport_type transport)
504 unsigned int code = 0;
508 code = pdu->hdr->coap_hdr_udp_t.code;
512 code = pdu->hdr->coap_hdr_tcp_t.header_data[1];
515 code = pdu->hdr->coap_hdr_tcp_8bit_t.header_data[2];
518 code = pdu->hdr->coap_hdr_tcp_16bit_t.header_data[3];
521 code = pdu->hdr->coap_hdr_tcp_32bit_t.header_data[5];
525 debug("it has wrong type\n");
530 int coap_add_token(coap_pdu_t *pdu, size_t len, const unsigned char *data,
531 coap_transport_type transport)
533 const size_t HEADERLENGTH = len + 4;
534 /* must allow for pdu == NULL as callers may rely on this */
535 if (!pdu || len > 8 || pdu->max_size < HEADERLENGTH)
538 unsigned char* token = NULL;
542 pdu->hdr->coap_hdr_udp_t.token_length = len;
543 token = pdu->hdr->coap_hdr_udp_t.token;
544 pdu->length = HEADERLENGTH;
548 pdu->hdr->coap_hdr_tcp_t.header_data[0] =
549 pdu->hdr->coap_hdr_tcp_t.header_data[0] | len;
550 token = pdu->hdr->coap_hdr_tcp_t.token;
551 pdu->length = len + COAP_TCP_HEADER_NO_FIELD;
554 pdu->hdr->coap_hdr_tcp_8bit_t.header_data[0] =
555 pdu->hdr->coap_hdr_tcp_8bit_t.header_data[0] | len;
556 token = pdu->hdr->coap_hdr_tcp_8bit_t.token;
557 pdu->length = len + COAP_TCP_HEADER_8_BIT;
560 pdu->hdr->coap_hdr_tcp_16bit_t.header_data[0] =
561 pdu->hdr->coap_hdr_tcp_16bit_t.header_data[0] | len;
562 token = pdu->hdr->coap_hdr_tcp_16bit_t.token;
563 pdu->length = len + COAP_TCP_HEADER_16_BIT;
566 pdu->hdr->coap_hdr_tcp_32bit_t.header_data[0] =
567 pdu->hdr->coap_hdr_tcp_32bit_t.header_data[0] | len;
568 token = pdu->hdr->coap_hdr_tcp_32bit_t.token;
569 pdu->length = len + COAP_TCP_HEADER_32_BIT;
573 debug("it has wrong type\n");
578 memcpy(token, data, len);
587 void coap_get_token(const coap_hdr_t *pdu_hdr, coap_transport_type transport,
588 unsigned char **token, unsigned int *token_length)
592 assert(token_length);
597 *token_length = pdu_hdr->coap_hdr_udp_t.token_length;
598 *token = (unsigned char *)pdu_hdr->coap_hdr_udp_t.token;
602 *token_length = (pdu_hdr->coap_hdr_tcp_t.header_data[0]) & 0x0f;
603 *token = (unsigned char *)pdu_hdr->coap_hdr_tcp_t.token;
606 *token_length = (pdu_hdr->coap_hdr_tcp_8bit_t.header_data[0]) & 0x0f;
607 *token = (unsigned char *)pdu_hdr->coap_hdr_tcp_8bit_t.token;
610 *token_length = (pdu_hdr->coap_hdr_tcp_16bit_t.header_data[0]) & 0x0f;
611 *token = (unsigned char *)pdu_hdr->coap_hdr_tcp_16bit_t.token;
614 *token_length = (pdu_hdr->coap_hdr_tcp_32bit_t.header_data[0]) & 0x0f;
615 *token = (unsigned char *)pdu_hdr->coap_hdr_tcp_32bit_t.token;
619 debug("it has wrong type\n");
623 /** @FIXME de-duplicate code with coap_add_option_later */
624 size_t coap_add_option(coap_pdu_t *pdu, unsigned short type, unsigned int len,
625 const unsigned char *data, coap_transport_type transport)
633 if (type < pdu->max_delta)
635 warn("coap_add_option: options are not in correct order\n");
643 opt = (unsigned char *) &(pdu->hdr->coap_hdr_tcp_t) + pdu->length;
646 opt = (unsigned char *) &(pdu->hdr->coap_hdr_tcp_8bit_t) + pdu->length;
649 opt = (unsigned char *) &(pdu->hdr->coap_hdr_tcp_16bit_t) + pdu->length;
652 opt = (unsigned char *) &(pdu->hdr->coap_hdr_tcp_32bit_t) + pdu->length;
656 opt = (unsigned char *) &(pdu->hdr->coap_hdr_udp_t) + pdu->length;
660 /* encode option and check length */
661 optsize = coap_opt_encode(opt, pdu->max_size - pdu->length, type - pdu->max_delta, data, len);
665 warn("coap_add_option: cannot add option\n");
671 pdu->max_delta = type;
672 pdu->length += optsize;
678 /** @FIXME de-duplicate code with coap_add_option */
680 coap_add_option_later(coap_pdu_t *pdu, unsigned short type, unsigned int len)
688 if (type < pdu->max_delta)
690 warn("coap_add_option: options are not in correct order\n");
694 opt = (unsigned char *) pdu->hdr + pdu->length;
696 /* encode option and check length */
697 optsize = coap_opt_encode(opt, pdu->max_size - pdu->length, type - pdu->max_delta, NULL, len);
701 warn("coap_add_option: cannot add option\n");
707 pdu->max_delta = type;
708 pdu->length += optsize;
711 return ((unsigned char*) opt) + optsize - len;
714 int coap_add_data(coap_pdu_t *pdu, unsigned int len, const unsigned char *data)
717 assert(pdu->data == NULL);
722 if (pdu->length + len + 1 > pdu->max_size)
724 warn("coap_add_data: cannot add: data too large for PDU\n");
725 assert(pdu->data == NULL);
729 pdu->data = (unsigned char *) pdu->hdr + pdu->length;
730 *pdu->data = COAP_PAYLOAD_START;
733 memcpy(pdu->data, data, len);
734 pdu->length += len + 1;
738 int coap_get_data(const coap_pdu_t *pdu, size_t *len, unsigned char **data)
746 *len = (unsigned char *) pdu->hdr + pdu->length - pdu->data;
750 { /* no data, clear everything */
755 return *data != NULL;
758 #ifndef SHORT_ERROR_RESPONSE
765 /* if you change anything here, make sure, that the longest string does not
766 * exceed COAP_ERROR_PHRASE_LENGTH. */
767 error_desc_t coap_error[] =
769 { COAP_RESPONSE_CODE(65), "2.01 Created" },
770 { COAP_RESPONSE_CODE(66), "2.02 Deleted" },
771 { COAP_RESPONSE_CODE(67), "2.03 Valid" },
772 { COAP_RESPONSE_CODE(68), "2.04 Changed" },
773 { COAP_RESPONSE_CODE(69), "2.05 Content" },
774 { COAP_RESPONSE_CODE(400), "Bad Request" },
775 { COAP_RESPONSE_CODE(401), "Unauthorized" },
776 { COAP_RESPONSE_CODE(402), "Bad Option" },
777 { COAP_RESPONSE_CODE(403), "Forbidden" },
778 { COAP_RESPONSE_CODE(404), "Not Found" },
779 { COAP_RESPONSE_CODE(405), "Method Not Allowed" },
780 { COAP_RESPONSE_CODE(408), "Request Entity Incomplete" },
781 { COAP_RESPONSE_CODE(413), "Request Entity Too Large" },
782 { COAP_RESPONSE_CODE(415), "Unsupported Media Type" },
783 { COAP_RESPONSE_CODE(500), "Internal Server Error" },
784 { COAP_RESPONSE_CODE(501), "Not Implemented" },
785 { COAP_RESPONSE_CODE(502), "Bad Gateway" },
786 { COAP_RESPONSE_CODE(503), "Service Unavailable" },
787 { COAP_RESPONSE_CODE(504), "Gateway Timeout" },
788 { COAP_RESPONSE_CODE(505), "Proxying Not Supported" },
789 { 0, NULL } /* end marker */
793 coap_response_phrase(unsigned char code)
796 for (i = 0; coap_error[i].code; ++i)
798 if (coap_error[i].code == code)
799 return coap_error[i].phrase;
806 * Advances *optp to next option if still in PDU. This function
807 * returns the number of bytes opt has been advanced or @c 0
810 static size_t next_option_safe(coap_opt_t **optp, size_t *length, coap_option_t* option)
812 //coap_option_t option;
818 optsize = coap_opt_parse(*optp, *length, option);
821 assert(optsize <= *length);
830 int coap_pdu_parse(unsigned char *data, size_t length, coap_pdu_t *pdu,
831 coap_transport_type transport)
836 if (pdu->max_size < length)
838 debug("insufficient space to store parsed PDU\n");
839 printf("[COAP] insufficient space to store parsed PDU\n");
843 unsigned int headerSize = 0;
845 if (coap_udp == transport)
847 headerSize = sizeof(pdu->hdr->coap_hdr_udp_t);
852 headerSize = coap_get_tcp_header_length_for_transport(transport);
856 if (length < headerSize)
858 debug("discarded invalid PDU\n");
861 coap_opt_t *opt = NULL;
862 unsigned int tokenLength = 0;
869 for (size_t i = 0 ; i < headerSize ; i++)
871 pdu->hdr->coap_hdr_tcp_t.header_data[i] = data[i];
874 tokenLength = data[0] & 0x0f;
875 opt = (unsigned char *) (&(pdu->hdr->coap_hdr_tcp_t) + 1) + tokenLength;
878 for (size_t i = 0 ; i < headerSize ; i++)
880 pdu->hdr->coap_hdr_tcp_8bit_t.header_data[i] = data[i];
883 tokenLength = data[0] & 0x0f;
884 opt = (unsigned char *) (&(pdu->hdr->coap_hdr_tcp_8bit_t))
885 + tokenLength + COAP_TCP_HEADER_8_BIT;
888 for (size_t i = 0 ; i < headerSize ; i++)
890 pdu->hdr->coap_hdr_tcp_16bit_t.header_data[i] = data[i];
893 tokenLength = data[0] & 0x0f;
894 opt = (unsigned char *) (&(pdu->hdr->coap_hdr_tcp_16bit_t) + 1) + tokenLength;
897 for (size_t i = 0 ; i < headerSize ; i++)
899 pdu->hdr->coap_hdr_tcp_32bit_t.header_data[i] = data[i];
902 tokenLength = data[0] & 0x0f;
903 opt = ((unsigned char *) &(pdu->hdr->coap_hdr_tcp_32bit_t)) +
904 headerSize + tokenLength;
907 printf("it has wrong type\n");
910 pdu->length = length;
912 if (coap_udp == transport)
914 pdu->hdr->coap_hdr_udp_t.version = data[0] >> 6;
915 pdu->hdr->coap_hdr_udp_t.type = (data[0] >> 4) & 0x03;
916 pdu->hdr->coap_hdr_udp_t.token_length = data[0] & 0x0f;
917 pdu->hdr->coap_hdr_udp_t.code = data[1];
920 tokenLength = pdu->hdr->coap_hdr_udp_t.token_length;
923 if (pdu->hdr->coap_hdr_udp_t.code == 0)
925 if (length != headerSize || tokenLength)
927 debug("coap_pdu_parse: empty message is not empty\n");
932 if (length < headerSize + tokenLength || tokenLength > 8)
934 debug("coap_pdu_parse: invalid Token\n");
938 memcpy(&pdu->hdr->coap_hdr_udp_t.id, data + 2, 2);
940 /* Finally calculate beginning of data block and thereby check integrity
941 * of the PDU structure. */
943 /* append data (including the Token) to pdu structure */
944 memcpy(&(pdu->hdr->coap_hdr_udp_t) + 1, data + headerSize, length - headerSize);
946 /* skip header + token */
947 length -= (tokenLength + headerSize);
948 opt = (unsigned char *) (&(pdu->hdr->coap_hdr_udp_t) + 1) + tokenLength;
951 else // common for tcp header setting
955 if (length < headerSize + tokenLength || tokenLength > 8)
957 debug("coap_pdu_parse: invalid Token\n");
960 /* Finally calculate beginning of data block and thereby check integrity
961 * of the PDU structure. */
963 /* append data (including the Token) to pdu structure */
964 memcpy(((unsigned char *) pdu->hdr) + headerSize,
965 data + headerSize, length - headerSize);
967 /* skip header + token */
968 length -= (tokenLength + headerSize);
972 while (length && *opt != COAP_PAYLOAD_START)
974 coap_option_t option;
975 memset(&option, 0, sizeof(coap_option_t));
976 if (!next_option_safe(&opt, (size_t *) &length, &option))
978 debug("coap_pdu_parse: drop\n");
983 /* end of packet or start marker */
986 assert(*opt == COAP_PAYLOAD_START);
992 debug("coap_pdu_parse: message ending in payload start marker\n");
997 "set data to %p (pdu ends at %p)\n", (unsigned char *)opt,
998 (unsigned char *)pdu->hdr + pdu->length);
999 pdu->data = (unsigned char *) opt;
1000 //printf("[COAP] pdu - data : %s\n", pdu->data);