libcoap  4.3.0rc1
pdu.h
Go to the documentation of this file.
1 /*
2  * pdu.h -- CoAP message structure
3  *
4  * Copyright (C) 2010-2014 Olaf Bergmann <bergmann@tzi.org>
5  *
6  * This file is part of the CoAP library libcoap. Please see README for terms
7  * of use.
8  */
9 
15 #ifndef COAP_PDU_H_
16 #define COAP_PDU_H_
17 
18 #include "uri.h"
19 #include "option.h"
20 
21 #ifdef WITH_LWIP
22 #include <lwip/pbuf.h>
23 #endif
24 
25 #include <stdint.h>
26 
27 #define COAP_DEFAULT_PORT 5683 /* CoAP default UDP/TCP port */
28 #define COAPS_DEFAULT_PORT 5684 /* CoAP default UDP/TCP port for secure transmission */
29 #define COAP_DEFAULT_MAX_AGE 60 /* default maximum object lifetime in seconds */
30 #ifndef COAP_DEFAULT_MTU
31 #define COAP_DEFAULT_MTU 1152
32 #endif /* COAP_DEFAULT_MTU */
33 
34 #ifndef COAP_DEFAULT_HOP_LIMIT
35 #define COAP_DEFAULT_HOP_LIMIT 16
36 #endif /* COAP_DEFAULT_HOP_LIMIT */
37 
38 /* TCP Message format constants, do not modify */
39 #define COAP_MESSAGE_SIZE_OFFSET_TCP8 13
40 #define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
41 #define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
42 
43 /* Derived message size limits */
44 #define COAP_MAX_MESSAGE_SIZE_TCP0 (COAP_MESSAGE_SIZE_OFFSET_TCP8-1) /* 12 */
45 #define COAP_MAX_MESSAGE_SIZE_TCP8 (COAP_MESSAGE_SIZE_OFFSET_TCP16-1) /* 268 */
46 #define COAP_MAX_MESSAGE_SIZE_TCP16 (COAP_MESSAGE_SIZE_OFFSET_TCP32-1) /* 65804 */
47 #define COAP_MAX_MESSAGE_SIZE_TCP32 (COAP_MESSAGE_SIZE_OFFSET_TCP32+0xFFFFFFFF)
48 
49 #ifndef COAP_DEFAULT_MAX_PDU_RX_SIZE
50 #if defined(WITH_CONTIKI) || defined(WITH_LWIP)
51 #define COAP_DEFAULT_MAX_PDU_RX_SIZE (COAP_MAX_MESSAGE_SIZE_TCP16+4UL)
52 #else
53 /* 8 MiB max-message-size plus some space for options */
54 #define COAP_DEFAULT_MAX_PDU_RX_SIZE (8UL*1024*1024+256)
55 #endif
56 #endif /* COAP_DEFAULT_MAX_PDU_RX_SIZE */
57 
58 #ifndef COAP_DEBUG_BUF_SIZE
59 #if defined(WITH_CONTIKI) || defined(WITH_LWIP)
60 #define COAP_DEBUG_BUF_SIZE 128
61 #else /* defined(WITH_CONTIKI) || defined(WITH_LWIP) */
62 /* 1024 derived from RFC7252 4.6. Message Size max payload */
63 #define COAP_DEBUG_BUF_SIZE (8 + 1024 * 2)
64 #endif /* defined(WITH_CONTIKI) || defined(WITH_LWIP) */
65 #endif /* COAP_DEBUG_BUF_SIZE */
66 
67 #define COAP_DEFAULT_VERSION 1 /* version of CoAP supported */
68 #define COAP_DEFAULT_SCHEME "coap" /* the default scheme for CoAP URIs */
69 
71 #define COAP_DEFAULT_URI_WELLKNOWN ".well-known/core"
72 
73 /* CoAP message types */
74 
75 #define COAP_MESSAGE_CON 0 /* confirmable message (requires ACK/RST) */
76 #define COAP_MESSAGE_NON 1 /* non-confirmable message (one-shot message) */
77 #define COAP_MESSAGE_ACK 2 /* used to acknowledge confirmable messages */
78 #define COAP_MESSAGE_RST 3 /* indicates error in received messages */
79 
80 /* CoAP request methods */
81 
82 typedef enum coap_request_t {
87  COAP_REQUEST_FETCH, /* 5 RFC 8132 */
88  COAP_REQUEST_PATCH, /* 6 RFC 8132 */
89  COAP_REQUEST_IPATCH, /* 7 RFC 8132 */
91 
92 /*
93  * CoAP option types (be sure to update coap_option_check_critical() and
94  * coap_add_option() when adding options
95  */
96 
97 /*
98  * The C, U, and N flags indicate the properties
99  * Critical, Unsafe, and NoCacheKey, respectively.
100  * If U is set, then N has no meaning as per
101  * https://tools.ietf.org/html/rfc7252#section-5.10
102  * and is set to a -.
103  *
104  * Separately, R is for the options that can be repeated
105  *
106  * The least significant byte of the option is set as followed
107  * as per https://tools.ietf.org/html/rfc7252#section-5.4.6
108  *
109  * 0 1 2 3 4 5 6 7
110  * --+---+---+---+---+---+---+---+
111  * | NoCacheKey| U | C |
112  * --+---+---+---+---+---+---+---+
113  *
114  * https://tools.ietf.org/html/rfc8613#section-4 goes on to define E, I and U
115  * properties Encrypted and Integrity Protected, Integrity Protected Only, and
116  * Unprotected respectively. Integrity Protected Only is not currently used.
117  *
118  * An Option is tagged with CUNREIU with any of the letters replaced with _ if
119  * not set, or - for N if U is set (see above) for aiding understanding of the
120  * Option.
121  */
122 
123 #define COAP_OPTION_IF_MATCH 1 /* C__RE__, opaque, 0-8 B, RFC7252 */
124 #define COAP_OPTION_URI_HOST 3 /* CU-___U, String, 1-255 B, RFC7252 */
125 #define COAP_OPTION_ETAG 4 /* ___RE__, opaque, 1-8 B, RFC7252 */
126 #define COAP_OPTION_IF_NONE_MATCH 5 /* C___E__, empty, 0 B, RFC7252 */
127 #define COAP_OPTION_OBSERVE 6 /* _U-_E_U, empty/uint,0/0-3 B, RFC7641 */
128 #define COAP_OPTION_URI_PORT 7 /* CU-___U, uint, 0-2 B, RFC7252 */
129 #define COAP_OPTION_LOCATION_PATH 8 /* ___RE__, String, 0-255 B, RFC7252 */
130 #define COAP_OPTION_OSCORE 9 /* C_____U, *, 0-255 B, RFC8613 */
131 #define COAP_OPTION_URI_PATH 11 /* CU-RE__, String, 0-255 B, RFC7252 */
132 #define COAP_OPTION_CONTENT_FORMAT 12 /* ____E__, uint, 0-2 B, RFC7252 */
133 #define COAP_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
134 /* COAP_OPTION_MAXAGE default 60 seconds if not set */
135 #define COAP_OPTION_MAXAGE 14 /* _U-_E_U, uint, 0-4 B, RFC7252 */
136 #define COAP_OPTION_URI_QUERY 15 /* CU-RE__, String, 1-255 B, RFC7252 */
137 #define COAP_OPTION_HOP_LIMIT 16 /* ______U, uint, 1 B, RFC8768 */
138 #define COAP_OPTION_ACCEPT 17 /* C___E__, uint, 0-2 B, RFC7252 */
139 #define COAP_OPTION_LOCATION_QUERY 20 /* ___RE__, String, 0-255 B, RFC7252 */
140 #define COAP_OPTION_BLOCK2 23 /* CU-_E_U, uint, 0-3 B, RFC7959 */
141 #define COAP_OPTION_BLOCK1 27 /* CU-_E_U, uint, 0-3 B, RFC7959 */
142 #define COAP_OPTION_SIZE2 28 /* __N_E_U, uint, 0-4 B, RFC7959 */
143 #define COAP_OPTION_PROXY_URI 35 /* CU-___U, String, 1-1034 B, RFC7252 */
144 #define COAP_OPTION_PROXY_SCHEME 39 /* CU-___U, String, 1-255 B, RFC7252 */
145 #define COAP_OPTION_SIZE1 60 /* __N_E_U, uint, 0-4 B, RFC7252 */
146 #define COAP_OPTION_NORESPONSE 258 /* _U-_E_U, uint, 0-1 B, RFC7967 */
147 
148 #define COAP_MAX_OPT 65535
150 /* CoAP result codes (HTTP-Code / 100 * 40 + HTTP-Code % 100) */
151 
152 /* As of draft-ietf-core-coap-04, response codes are encoded to base
153  * 32, i.e. the three upper bits determine the response class while
154  * the remaining five fine-grained information specific to that class.
155  */
156 #define COAP_RESPONSE_CODE(N) (((N)/100 << 5) | (N)%100)
157 
158 /* Determines the class of response code C */
159 #define COAP_RESPONSE_CLASS(C) (((C) >> 5) & 0xFF)
160 
161 #ifndef SHORT_ERROR_RESPONSE
172 const char *coap_response_phrase(unsigned char code);
173 
174 #define COAP_ERROR_PHRASE_LENGTH 32
176 #else
177 #define coap_response_phrase(x) ((char *)NULL)
178 
179 #define COAP_ERROR_PHRASE_LENGTH 0
180 #endif /* SHORT_ERROR_RESPONSE */
181 
182 #define COAP_SIGNALING_CODE(N) (((N)/100 << 5) | (N)%100)
183 #define COAP_SIGNALING_CSM COAP_SIGNALING_CODE(701)
184 #define COAP_SIGNALING_PING COAP_SIGNALING_CODE(702)
185 #define COAP_SIGNALING_PONG COAP_SIGNALING_CODE(703)
186 #define COAP_SIGNALING_RELEASE COAP_SIGNALING_CODE(704)
187 #define COAP_SIGNALING_ABORT COAP_SIGNALING_CODE(705)
188 
189 /* Applies to COAP_SIGNALING_CSM */
190 #define COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE 2
191 #define COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER 4
192 /* Applies to COAP_SIGNALING_PING / COAP_SIGNALING_PONG */
193 #define COAP_SIGNALING_OPTION_CUSTODY 2
194 /* Applies to COAP_SIGNALING_RELEASE */
195 #define COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS 2
196 #define COAP_SIGNALING_OPTION_HOLD_OFF 4
197 /* Applies to COAP_SIGNALING_ABORT */
198 #define COAP_SIGNALING_OPTION_BAD_CSM_OPTION 2
199 
200 /* CoAP media type encoding */
201 
202 #define COAP_MEDIATYPE_TEXT_PLAIN 0 /* text/plain (UTF-8) */
203 #define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT 40 /* application/link-format */
204 #define COAP_MEDIATYPE_APPLICATION_XML 41 /* application/xml */
205 #define COAP_MEDIATYPE_APPLICATION_OCTET_STREAM 42 /* application/octet-stream */
206 #define COAP_MEDIATYPE_APPLICATION_RDF_XML 43 /* application/rdf+xml */
207 #define COAP_MEDIATYPE_APPLICATION_EXI 47 /* application/exi */
208 #define COAP_MEDIATYPE_APPLICATION_JSON 50 /* application/json */
209 #define COAP_MEDIATYPE_APPLICATION_CBOR 60 /* application/cbor */
210 #define COAP_MEDIATYPE_APPLICATION_CWT 61 /* application/cwt, RFC 8392 */
211 
212 /* Content formats from RFC 8152 */
213 #define COAP_MEDIATYPE_APPLICATION_COSE_SIGN 98 /* application/cose; cose-type="cose-sign" */
214 #define COAP_MEDIATYPE_APPLICATION_COSE_SIGN1 18 /* application/cose; cose-type="cose-sign1" */
215 #define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT 96 /* application/cose; cose-type="cose-encrypt" */
216 #define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0 16 /* application/cose; cose-type="cose-encrypt0" */
217 #define COAP_MEDIATYPE_APPLICATION_COSE_MAC 97 /* application/cose; cose-type="cose-mac" */
218 #define COAP_MEDIATYPE_APPLICATION_COSE_MAC0 17 /* application/cose; cose-type="cose-mac0" */
219 
220 #define COAP_MEDIATYPE_APPLICATION_COSE_KEY 101 /* application/cose-key */
221 #define COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET 102 /* application/cose-key-set */
222 
223 /* Content formats from RFC 8428 */
224 #define COAP_MEDIATYPE_APPLICATION_SENML_JSON 110 /* application/senml+json */
225 #define COAP_MEDIATYPE_APPLICATION_SENSML_JSON 111 /* application/sensml+json */
226 #define COAP_MEDIATYPE_APPLICATION_SENML_CBOR 112 /* application/senml+cbor */
227 #define COAP_MEDIATYPE_APPLICATION_SENSML_CBOR 113 /* application/sensml+cbor */
228 #define COAP_MEDIATYPE_APPLICATION_SENML_EXI 114 /* application/senml-exi */
229 #define COAP_MEDIATYPE_APPLICATION_SENSML_EXI 115 /* application/sensml-exi */
230 #define COAP_MEDIATYPE_APPLICATION_SENML_XML 310 /* application/senml+xml */
231 #define COAP_MEDIATYPE_APPLICATION_SENSML_XML 311 /* application/sensml+xml */
232 
233 /* Content formats from RFC 8782 */
234 #define COAP_MEDIATYPE_APPLICATION_DOTS_CBOR 271 /* application/dots+cbor */
235 
236 /* Note that identifiers for registered media types are in the range 0-65535. We
237  * use an unallocated type here and hope for the best. */
238 #define COAP_MEDIATYPE_ANY 0xff /* any media type */
239 
244 typedef int coap_mid_t;
245 
247 #define COAP_INVALID_MID -1
248 
253 #define COAP_DROPPED_RESPONSE -2
254 
255 #define COAP_PDU_DELAYED -3
256 
257 #define COAP_PAYLOAD_START 0xFF /* payload marker */
258 
266 COAP_DEPRECATED typedef struct {
267  uint16_t key; /* the option key (no delta coding) */
268  unsigned int length;
269 } coap_option;
270 
271 #define COAP_OPTION_KEY(option) (option).key
272 #define COAP_OPTION_LENGTH(option) (option).length
273 #define COAP_OPTION_DATA(option) ((unsigned char *)&(option) + sizeof(coap_option))
274 
287 struct coap_pdu_t {
288  uint8_t type;
289  uint8_t code;
290  uint8_t max_hdr_size;
291  uint8_t hdr_size;
292  uint8_t token_length;
293  uint16_t mid;
294  uint16_t max_opt;
295  size_t alloc_size;
296  size_t used_size;
297  size_t max_size;
298  uint8_t *token;
299  uint8_t *data;
300 #ifdef WITH_LWIP
301  struct pbuf *pbuf;
309 #endif
310  const uint8_t *body_data;
311  size_t body_length;
312  size_t body_offset;
313  size_t body_total;
316 };
317 
318 #define COAP_PDU_IS_EMPTY(pdu) ((pdu)->code == 0)
319 #define COAP_PDU_IS_REQUEST(pdu) (!COAP_PDU_IS_EMPTY(pdu) && (pdu)->code < 32)
320 #define COAP_PDU_IS_RESPONSE(pdu) ((pdu)->code >= 64 && (pdu)->code < 224)
321 #define COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224)
322 
323 #define COAP_PDU_MAX_UDP_HEADER_SIZE 4
324 #define COAP_PDU_MAX_TCP_HEADER_SIZE 6
325 
326 #ifdef WITH_LWIP
342 coap_pdu_t * coap_pdu_from_pbuf(struct pbuf *pbuf);
343 #endif
344 
345 typedef uint8_t coap_proto_t;
349 #define COAP_PROTO_NONE 0
350 #define COAP_PROTO_UDP 1
351 #define COAP_PROTO_DTLS 2
352 #define COAP_PROTO_TCP 3
353 #define COAP_PROTO_TLS 4
354 
391 };
392 
407 coap_pdu_t *
408 coap_pdu_init(uint8_t type, uint8_t code, uint16_t mid, size_t size);
409 
419 int coap_pdu_resize(coap_pdu_t *pdu, size_t new_size);
420 
432 int coap_pdu_check_resize(coap_pdu_t *pdu, size_t new_size);
433 
440 void coap_pdu_clear(coap_pdu_t *pdu, size_t size);
441 
449 coap_pdu_t *coap_new_pdu(const struct coap_session_t *session);
450 
459 void coap_delete_pdu(coap_pdu_t *pdu);
460 
474 coap_pdu_t *
475 coap_pdu_duplicate(const coap_pdu_t *old_pdu,
476  struct coap_session_t *session,
477  size_t token_length,
478  uint8_t *token,
479  coap_opt_filter_t *drop_options);
480 
491  const uint8_t *data);
492 
504 size_t coap_pdu_parse_size(coap_proto_t proto,
505  const uint8_t *data,
506  size_t length);
507 
516 
529 
544 int coap_pdu_parse(coap_proto_t proto,
545  const uint8_t *data,
546  size_t length,
547  coap_pdu_t *pdu);
561 int coap_add_token(coap_pdu_t *pdu,
562  size_t len,
563  const uint8_t *data);
564 
565 size_t coap_insert_option(coap_pdu_t *, uint16_t, size_t, const uint8_t *);
566 
580  size_t len,
581  const uint8_t *data);
582 
591 size_t coap_add_option(coap_pdu_t *pdu,
592  uint16_t type,
593  size_t len,
594  const uint8_t *data);
595 
596 
597 
603 int coap_remove_option(coap_pdu_t *pdu, uint16_t type);
604 
612 size_t coap_insert_option(coap_pdu_t *pdu, uint16_t type,
613  size_t len, const uint8_t *data);
614 
620 size_t coap_update_option(coap_pdu_t *pdu,
621  uint16_t type,
622  size_t len,
623  const uint8_t *data);
629 int coap_add_data(coap_pdu_t *pdu,
630  size_t len,
631  const uint8_t *data);
632 
640 uint8_t *coap_add_data_after(coap_pdu_t *pdu, size_t len);
641 
647 int coap_get_data(const coap_pdu_t *pdu,
648  size_t *len,
649  uint8_t **data);
650 
668 int coap_get_data_large(const coap_pdu_t *pdu,
669  size_t *len,
670  const uint8_t **data,
671  size_t *offset,
672  size_t *total);
673 
682 
683 #endif /* COAP_PDU_H_ */
#define COAP_DEPRECATED
Definition: libcoap.h:46
Helpers for handling options in CoAP PDUs.
coap_pdu_t * coap_pdu_duplicate(const coap_pdu_t *old_pdu, struct coap_session_t *session, size_t token_length, uint8_t *token, coap_opt_filter_t *drop_options)
Duplicate an existing PDU.
Definition: pdu.c:146
coap_response_code
Set of response codes available for a response packet.
Definition: pdu.h:360
@ COAP_RESPONSE_CODE_OK
Definition: pdu.h:361
@ COAP_RESPONSE_CODE_INTERNAL_ERROR
Definition: pdu.h:383
@ COAP_RESPONSE_CODE_HOP_LIMIT_REACHED
Definition: pdu.h:390
@ COAP_RESPONSE_CODE_PRECONDITION_FAILED
Definition: pdu.h:377
@ COAP_RESPONSE_CODE_NOT_ALLOWED
Definition: pdu.h:373
@ COAP_RESPONSE_CODE_CHANGED
Definition: pdu.h:365
@ COAP_RESPONSE_CODE_NOT_ACCEPTABLE
Definition: pdu.h:374
@ COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED
Definition: pdu.h:388
@ COAP_RESPONSE_CODE_BAD_REQUEST
Definition: pdu.h:368
@ COAP_RESPONSE_CODE_INCOMPLETE
Definition: pdu.h:375
@ COAP_RESPONSE_CODE_NOT_IMPLEMENTED
Definition: pdu.h:384
@ COAP_RESPONSE_CODE_NOT_FOUND
Definition: pdu.h:372
@ COAP_RESPONSE_CODE_BAD_GATEWAY
Definition: pdu.h:385
@ COAP_RESPONSE_CODE_BAD_OPTION
Definition: pdu.h:370
@ COAP_RESPONSE_CODE_REQUEST_TOO_LARGE
Definition: pdu.h:378
@ COAP_RESPONSE_CODE_TOO_MANY_REQUESTS
Definition: pdu.h:382
@ COAP_RESPONSE_CODE_CONFLICT
Definition: pdu.h:376
@ COAP_RESPONSE_CODE_DELETED
Definition: pdu.h:363
@ COAP_RESPONSE_CODE_UNAUTHORIZED
Definition: pdu.h:369
@ COAP_RESPONSE_CODE_CREATED
Definition: pdu.h:362
@ COAP_RESPONSE_CODE_CONTENT
Definition: pdu.h:366
@ COAP_RESPONSE_CODE_UNPROCESSABLE
Definition: pdu.h:381
@ COAP_RESPONSE_CODE_CONTINUE
Definition: pdu.h:367
@ COAP_RESPONSE_CODE_VALID
Definition: pdu.h:364
@ COAP_RESPONSE_CODE_UNSUPPORTED_CONTENT_FORMAT
Definition: pdu.h:379
@ COAP_RESPONSE_CODE_GATEWAY_TIMEOUT
Definition: pdu.h:387
@ COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE
Definition: pdu.h:386
@ COAP_RESPONSE_CODE_FORBIDDEN
Definition: pdu.h:371
int coap_update_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Updates token in pdu with length len and data.
Definition: pdu.c:273
void coap_delete_pdu(coap_pdu_t *pdu)
Dispose of an CoAP PDU and frees associated storage.
Definition: pdu.c:133
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
Definition: pdu.h:244
int coap_pdu_parse_header(coap_pdu_t *pdu, coap_proto_t proto)
Decode the protocol specific header for the specified PDU.
Definition: pdu.c:818
size_t coap_pdu_parse_header_size(coap_proto_t proto, const uint8_t *data)
Interprets data to determine the number of bytes in the header.
Definition: pdu.c:763
coap_request_t
Definition: pdu.h:82
@ COAP_REQUEST_PUT
Definition: pdu.h:85
@ COAP_REQUEST_DELETE
Definition: pdu.h:86
@ COAP_REQUEST_GET
Definition: pdu.h:83
@ COAP_REQUEST_FETCH
Definition: pdu.h:87
@ COAP_REQUEST_PATCH
Definition: pdu.h:88
@ COAP_REQUEST_IPATCH
Definition: pdu.h:89
@ COAP_REQUEST_POST
Definition: pdu.h:84
coap_pdu_t * coap_pdu_init(uint8_t type, uint8_t code, uint16_t mid, size_t size)
Creates a new CoAP PDU with at least enough storage space for the given size maximum message size.
Definition: pdu.c:85
#define COAP_RESPONSE_CODE(N)
Definition: pdu.h:156
int coap_get_data(const coap_pdu_t *pdu, size_t *len, uint8_t **data)
Retrieves the length and data pointer of specified PDU.
Definition: pdu.c:644
int coap_add_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds token of length len to pdu.
Definition: pdu.c:249
coap_pdu_t * coap_new_pdu(const struct coap_session_t *session)
Creates a new CoAP PDU.
Definition: pdu.c:125
void coap_pdu_clear(coap_pdu_t *pdu, size_t size)
Clears any contents from pdu and resets used_size, and data pointers.
Definition: pdu.c:35
uint8_t coap_proto_t
Definition: pdu.h:345
size_t coap_add_option(coap_pdu_t *pdu, uint16_t type, size_t len, const uint8_t *data)
Adds option of given type to pdu that is passed as first parameter.
Definition: pdu.c:535
int coap_pdu_parse_opt(coap_pdu_t *pdu)
Verify consistency in the given CoAP PDU structure and locate the data.
Definition: pdu.c:970
uint8_t * coap_add_data_after(coap_pdu_t *pdu, size_t len)
Adds given data to the pdu that is passed as first parameter but does not copy it.
Definition: pdu.c:626
size_t coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto)
Compose the protocol specific header for the specified PDU.
Definition: pdu.c:1120
int coap_pdu_parse(coap_proto_t proto, const uint8_t *data, size_t length, coap_pdu_t *pdu)
Parses data into the CoAP PDU structure given in result.
Definition: pdu.c:1095
int coap_get_data_large(const coap_pdu_t *pdu, size_t *len, const uint8_t **data, size_t *offset, size_t *total)
Retrieves the data from a PDU, with support for large bodies of data that spans multiple PDUs.
Definition: pdu.c:658
const char * coap_response_phrase(unsigned char code)
Returns a human-readable response phrase for the specified CoAP response code.
Definition: pdu.c:722
size_t coap_update_option(coap_pdu_t *pdu, uint16_t type, size_t len, const uint8_t *data)
Updates existing first option of given type in the pdu with the new data.
Definition: pdu.c:494
size_t coap_insert_option(coap_pdu_t *, uint16_t, size_t, const uint8_t *)
Inserts option of given type in the pdu with the appropriate data.
Definition: pdu.c:405
int coap_pdu_check_resize(coap_pdu_t *pdu, size_t new_size)
Dynamically grows the size of pdu to new_size if needed.
Definition: pdu.c:232
size_t coap_pdu_parse_size(coap_proto_t proto, const uint8_t *data, size_t length)
Parses data to extract the message size.
Definition: pdu.c:786
int coap_pdu_resize(coap_pdu_t *pdu, size_t new_size)
Dynamically grows the size of pdu to new_size.
Definition: pdu.c:198
int coap_remove_option(coap_pdu_t *pdu, uint16_t type)
Removes option of given type from the pdu.
Definition: pdu.c:305
int coap_add_data(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds given data to the pdu that is passed as first parameter.
Definition: pdu.c:614
Structure to hold large body (many blocks) transmission information.
unsigned int length
Definition: pdu.h:268
uint16_t key
Definition: pdu.h:267
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
Definition: pdu.h:287
uint8_t max_hdr_size
space reserved for protocol-specific header
Definition: pdu.h:290
uint8_t type
message type
Definition: pdu.h:288
uint16_t max_opt
highest option number in PDU
Definition: pdu.h:294
uint8_t * token
first byte of token, if any, or options
Definition: pdu.h:298
coap_lg_xmit_t * lg_xmit
Holds ptr to lg_xmit if sending a set of blocks.
Definition: pdu.h:314
size_t body_length
Holds body data length.
Definition: pdu.h:311
size_t max_size
maximum size for token, options and payload, or zero for variable size pdu
Definition: pdu.h:297
const uint8_t * body_data
Holds ptr to re-assembled data or NULL.
Definition: pdu.h:310
size_t body_offset
Holds body data offset.
Definition: pdu.h:312
uint8_t code
request method (value 1–31) or response code (value 64-255)
Definition: pdu.h:289
uint16_t mid
message id, if any, in regular host byte order
Definition: pdu.h:293
uint8_t token_length
length of Token
Definition: pdu.h:292
uint8_t hdr_size
actual size used for protocol-specific header
Definition: pdu.h:291
uint8_t * data
first byte of payload, if any
Definition: pdu.h:299
size_t used_size
used bytes of storage for token, options and payload
Definition: pdu.h:296
size_t alloc_size
allocated storage for token, options and payload
Definition: pdu.h:295
size_t body_total
Holds body data total size.
Definition: pdu.h:313