libcoap 4.3.2rc2

coap_pdu.h
Go to the documentation of this file.
1/*
2 * coap_pdu.h -- CoAP message structure
3 *
4 * Copyright (C) 2010-2014 Olaf Bergmann <bergmann@tzi.org>
5 * Copyright (C) 2021-2023 Jon Shallow <supjps-libcoap@jpshallow.com>
6 *
7 * SPDX-License-Identifier: BSD-2-Clause
8 *
9 * This file is part of the CoAP library libcoap. Please see README for terms
10 * of use.
11 */
12
18#ifndef COAP_PDU_H_
19#define COAP_PDU_H_
20
21#include "coap_option.h"
22#include "coap_uri.h"
23
24#ifdef WITH_LWIP
25#include <lwip/pbuf.h>
26#endif
27
28#include <stdint.h>
29
37#define COAP_DEFAULT_PORT 5683 /* CoAP default UDP/TCP port */
38#define COAPS_DEFAULT_PORT 5684 /* CoAP default UDP/TCP port for secure transmission */
39#define COAP_DEFAULT_MAX_AGE 60 /* default maximum object lifetime in seconds */
40#ifndef COAP_DEFAULT_MTU
41#define COAP_DEFAULT_MTU 1152
42#endif /* COAP_DEFAULT_MTU */
43
44#define COAP_BERT_BASE 1152
45
46#ifndef COAP_DEFAULT_HOP_LIMIT
47#define COAP_DEFAULT_HOP_LIMIT 16
48#endif /* COAP_DEFAULT_HOP_LIMIT */
49
50#define COAP_DEFAULT_SCHEME "coap" /* the default scheme for CoAP URIs */
51
53#define COAP_DEFAULT_URI_WELLKNOWN ".well-known/core"
54
55/* Extended Token constants */
56#define COAP_TOKEN_DEFAULT_MAX 8
57#define COAP_TOKEN_EXT_MAX 65804 /* 13 + 256 + 65535 */
58
59/* CoAP message types */
60
64 typedef enum coap_pdu_type_t {
65 COAP_MESSAGE_CON, /* 0 confirmable message (requires ACK/RST) */
66 COAP_MESSAGE_NON, /* 1 non-confirmable message (one-shot message) */
67 COAP_MESSAGE_ACK, /* 2 used to acknowledge confirmable messages */
68 COAP_MESSAGE_RST /* 3 indicates error in received messages */
69} coap_pdu_type_t;
70
74 typedef enum coap_request_t {
75 COAP_REQUEST_GET = 1,
76 COAP_REQUEST_POST, /* 2 */
77 COAP_REQUEST_PUT, /* 3 */
78 COAP_REQUEST_DELETE, /* 4 */
79 COAP_REQUEST_FETCH, /* 5 RFC 8132 */
80 COAP_REQUEST_PATCH, /* 6 RFC 8132 */
81 COAP_REQUEST_IPATCH, /* 7 RFC 8132 */
82} coap_request_t;
83
84/*
85 * CoAP option numbers (be sure to update coap_option_check_critical() and
86 * coap_add_option() when adding options
87 */
88
89/*
90 * The C, U, and N flags indicate the properties
91 * Critical, Unsafe, and NoCacheKey, respectively.
92 * If U is set, then N has no meaning as per
93 * https://rfc-editor.org/rfc/rfc7252#section-5.10
94 * and is set to a -.
95 *
96 * Separately, R is for the options that can be repeated
97 *
98 * The least significant byte of the option is set as followed
99 * as per https://rfc-editor.org/rfc/rfc7252#section-5.4.6
100 *
101 * 0 1 2 3 4 5 6 7
102 * --+---+---+---+---+---+---+---+
103 * | NoCacheKey| U | C |
104 * --+---+---+---+---+---+---+---+
105 *
106 * https://rfc-editor.org/rfc/rfc8613#section-4 goes on to define E, I and U
107 * properties Encrypted and Integrity Protected, Integrity Protected Only, and
108 * Unprotected respectively. Integrity Protected Only is not currently used.
109 *
110 * An Option is tagged with CUNREIU with any of the letters replaced with _ if
111 * not set, or - for N if U is set (see above) for aiding understanding of the
112 * Option.
113 */
114
115#define COAP_OPTION_IF_MATCH 1 /* C__RE__, opaque, 0-8 B, RFC7252 */
116#define COAP_OPTION_URI_HOST 3 /* CU-___U, String, 1-255 B, RFC7252 */
117#define COAP_OPTION_ETAG 4 /* ___RE__, opaque, 1-8 B, RFC7252 */
118#define COAP_OPTION_IF_NONE_MATCH 5 /* C___E__, empty, 0 B, RFC7252 */
119#define COAP_OPTION_OBSERVE 6 /* _U-_E_U, empty/uint,0/0-3 B, RFC7641 */
120#define COAP_OPTION_URI_PORT 7 /* CU-___U, uint, 0-2 B, RFC7252 */
121#define COAP_OPTION_LOCATION_PATH 8 /* ___RE__, String, 0-255 B, RFC7252 */
122#define COAP_OPTION_OSCORE 9 /* C_____U, *, 0-255 B, RFC8613 */
123#define COAP_OPTION_URI_PATH 11 /* CU-RE__, String, 0-255 B, RFC7252 */
124#define COAP_OPTION_CONTENT_FORMAT 12 /* ____E__, uint, 0-2 B, RFC7252 */
125#define COAP_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
126/* COAP_OPTION_MAXAGE default 60 seconds if not set */
127#define COAP_OPTION_MAXAGE 14 /* _U-_E_U, uint, 0-4 B, RFC7252 */
128#define COAP_OPTION_URI_QUERY 15 /* CU-RE__, String, 1-255 B, RFC7252 */
129#define COAP_OPTION_HOP_LIMIT 16 /* ______U, uint, 1 B, RFC8768 */
130#define COAP_OPTION_ACCEPT 17 /* C___E__, uint, 0-2 B, RFC7252 */
131#define COAP_OPTION_Q_BLOCK1 19 /* CU__E_U, uint, 0-3 B, RFC9177 */
132#define COAP_OPTION_LOCATION_QUERY 20 /* ___RE__, String, 0-255 B, RFC7252 */
133#define COAP_OPTION_BLOCK2 23 /* CU-_E_U, uint, 0-3 B, RFC7959 */
134#define COAP_OPTION_BLOCK1 27 /* CU-_E_U, uint, 0-3 B, RFC7959 */
135#define COAP_OPTION_SIZE2 28 /* __N_E_U, uint, 0-4 B, RFC7959 */
136#define COAP_OPTION_Q_BLOCK2 31 /* CU_RE_U, uint, 0-3 B, RFC9177 */
137#define COAP_OPTION_PROXY_URI 35 /* CU-___U, String, 1-1034 B, RFC7252 */
138#define COAP_OPTION_PROXY_SCHEME 39 /* CU-___U, String, 1-255 B, RFC7252 */
139#define COAP_OPTION_SIZE1 60 /* __N_E_U, uint, 0-4 B, RFC7252 */
140#define COAP_OPTION_ECHO 252 /* _N__E_U, opaque, 0-40 B, RFC9175 */
141#define COAP_OPTION_NORESPONSE 258 /* _U-_E_U, uint, 0-1 B, RFC7967 */
142#define COAP_OPTION_RTAG 292 /* ___RE_U, opaque, 0-8 B, RFC9175 */
143
144#define COAP_MAX_OPT 65535
146/* CoAP result codes (HTTP-Code / 100 * 40 + HTTP-Code % 100) */
147
148/* As of draft-ietf-core-coap-04, response codes are encoded to base
149 * 32, i.e. the three upper bits determine the response class while
150 * the remaining five fine-grained information specific to that class.
151 */
152#define COAP_RESPONSE_CODE(N) (((N)/100 << 5) | (N)%100)
153
154/* Determines the class of response code C */
155#define COAP_RESPONSE_CLASS(C) (((C) >> 5) & 0xFF)
156
157#ifndef SHORT_ERROR_RESPONSE
168 const char *coap_response_phrase(unsigned char code);
169
170#define COAP_ERROR_PHRASE_LENGTH 32
172#else
173#define coap_response_phrase(x) ((char *)NULL)
174
175#define COAP_ERROR_PHRASE_LENGTH 0
176#endif /* SHORT_ERROR_RESPONSE */
177
178#define COAP_SIGNALING_CODE(N) (((N)/100 << 5) | (N)%100)
179
180 typedef enum coap_pdu_signaling_proto_t {
181 COAP_SIGNALING_CSM = COAP_SIGNALING_CODE(701),
182 COAP_SIGNALING_PING = COAP_SIGNALING_CODE(702),
183 COAP_SIGNALING_PONG = COAP_SIGNALING_CODE(703),
184 COAP_SIGNALING_RELEASE = COAP_SIGNALING_CODE(704),
185 COAP_SIGNALING_ABORT = COAP_SIGNALING_CODE(705),
186} coap_pdu_signaling_proto_t;
187
188/* Applies to COAP_SIGNALING_CSM */
189#define COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE 2
190#define COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER 4
191#define COAP_SIGNALING_OPTION_EXTENDED_TOKEN_LENGTH 6
192
193/* Applies to COAP_SIGNALING_PING / COAP_SIGNALING_PONG */
194#define COAP_SIGNALING_OPTION_CUSTODY 2
195
196/* Applies to COAP_SIGNALING_RELEASE */
197#define COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS 2
198#define COAP_SIGNALING_OPTION_HOLD_OFF 4
199
200/* Applies to COAP_SIGNALING_ABORT */
201#define COAP_SIGNALING_OPTION_BAD_CSM_OPTION 2
202
203/* CoAP media type encoding */
204
205#define COAP_MEDIATYPE_TEXT_PLAIN 0 /* text/plain (UTF-8) */
206#define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT 40 /* application/link-format */
207#define COAP_MEDIATYPE_APPLICATION_XML 41 /* application/xml */
208#define COAP_MEDIATYPE_APPLICATION_OCTET_STREAM 42 /* application/octet-stream */
209#define COAP_MEDIATYPE_APPLICATION_RDF_XML 43 /* application/rdf+xml */
210#define COAP_MEDIATYPE_APPLICATION_EXI 47 /* application/exi */
211#define COAP_MEDIATYPE_APPLICATION_JSON 50 /* application/json */
212#define COAP_MEDIATYPE_APPLICATION_CBOR 60 /* application/cbor */
213#define COAP_MEDIATYPE_APPLICATION_CWT 61 /* application/cwt, RFC 8392 */
214
215/* Content formats from RFC 7390 */
216#define COAP_MEDIATYPE_APPLICATION_COAP_GROUP_JSON 256 /* application/coap-group+json */
217
218/* Content formats from RFC 8152 */
219#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN 98 /* application/cose; cose-type="cose-sign" */
220#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN1 18 /* application/cose; cose-type="cose-sign1" */
221#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT 96 /* application/cose; cose-type="cose-encrypt" */
222#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0 16 /* application/cose; cose-type="cose-encrypt0" */
223#define COAP_MEDIATYPE_APPLICATION_COSE_MAC 97 /* application/cose; cose-type="cose-mac" */
224#define COAP_MEDIATYPE_APPLICATION_COSE_MAC0 17 /* application/cose; cose-type="cose-mac0" */
225
226#define COAP_MEDIATYPE_APPLICATION_COSE_KEY 101 /* application/cose-key */
227#define COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET 102 /* application/cose-key-set */
228
229/* Content formats from RFC 8428 */
230#define COAP_MEDIATYPE_APPLICATION_SENML_JSON 110 /* application/senml+json */
231#define COAP_MEDIATYPE_APPLICATION_SENSML_JSON 111 /* application/sensml+json */
232#define COAP_MEDIATYPE_APPLICATION_SENML_CBOR 112 /* application/senml+cbor */
233#define COAP_MEDIATYPE_APPLICATION_SENSML_CBOR 113 /* application/sensml+cbor */
234#define COAP_MEDIATYPE_APPLICATION_SENML_EXI 114 /* application/senml-exi */
235#define COAP_MEDIATYPE_APPLICATION_SENSML_EXI 115 /* application/sensml-exi */
236#define COAP_MEDIATYPE_APPLICATION_SENML_XML 310 /* application/senml+xml */
237#define COAP_MEDIATYPE_APPLICATION_SENSML_XML 311 /* application/sensml+xml */
238
239/* Content formats from RFC 8782 */
240#define COAP_MEDIATYPE_APPLICATION_DOTS_CBOR 271 /* application/dots+cbor */
241
242/* Content formats from RFC 9200 */
243#define COAP_MEDIATYPE_APPLICATION_ACE_CBOR 19 /* application/ace+cbor */
244
245/* Content formats from RFC9177 */
246#define COAP_MEDIATYPE_APPLICATION_MB_CBOR_SEQ 272 /* application/missing-blocks+cbor-seq */
247
248/* Content formats from RFC 8613 */
249#define COAP_MEDIATYPE_APPLICATION_OSCORE 10001 /* application/oscore */
250
255 typedef int coap_mid_t;
256
258#define COAP_INVALID_MID -1
259
264#define COAP_INVALID_TID COAP_INVALID_MID
265
273 COAP_DEPRECATED typedef struct {
274 uint16_t key; /* the option key (no delta coding) */
275 unsigned int length;
276} coap_option;
277
278#define COAP_OPTION_KEY(option) (option).key
279#define COAP_OPTION_LENGTH(option) (option).length
280#define COAP_OPTION_DATA(option) ((unsigned char *)&(option) + sizeof(coap_option))
281
282#ifdef WITH_LWIP
298 coap_pdu_t *coap_pdu_from_pbuf(struct pbuf *pbuf);
299#endif
300
304 typedef enum coap_proto_t {
305 COAP_PROTO_NONE = 0,
306 COAP_PROTO_UDP,
307 COAP_PROTO_DTLS,
308 COAP_PROTO_TCP,
309 COAP_PROTO_TLS,
310 COAP_PROTO_WS,
311 COAP_PROTO_WSS,
312 COAP_PROTO_LAST
313} coap_proto_t;
314
318 typedef enum coap_pdu_code_t {
319 COAP_EMPTY_CODE = 0,
320
321 COAP_REQUEST_CODE_GET = COAP_REQUEST_GET,
322 COAP_REQUEST_CODE_POST = COAP_REQUEST_POST,
323 COAP_REQUEST_CODE_PUT = COAP_REQUEST_PUT,
324 COAP_REQUEST_CODE_DELETE = COAP_REQUEST_DELETE,
325 COAP_REQUEST_CODE_FETCH = COAP_REQUEST_FETCH,
326 COAP_REQUEST_CODE_PATCH = COAP_REQUEST_PATCH,
327 COAP_REQUEST_CODE_IPATCH = COAP_REQUEST_IPATCH,
328
329 COAP_RESPONSE_CODE_CREATED = COAP_RESPONSE_CODE(201),
330 COAP_RESPONSE_CODE_DELETED = COAP_RESPONSE_CODE(202),
331 COAP_RESPONSE_CODE_VALID = COAP_RESPONSE_CODE(203),
332 COAP_RESPONSE_CODE_CHANGED = COAP_RESPONSE_CODE(204),
333 COAP_RESPONSE_CODE_CONTENT = COAP_RESPONSE_CODE(205),
334 COAP_RESPONSE_CODE_CONTINUE = COAP_RESPONSE_CODE(231),
335 COAP_RESPONSE_CODE_BAD_REQUEST = COAP_RESPONSE_CODE(400),
336 COAP_RESPONSE_CODE_UNAUTHORIZED = COAP_RESPONSE_CODE(401),
337 COAP_RESPONSE_CODE_BAD_OPTION = COAP_RESPONSE_CODE(402),
338 COAP_RESPONSE_CODE_FORBIDDEN = COAP_RESPONSE_CODE(403),
339 COAP_RESPONSE_CODE_NOT_FOUND = COAP_RESPONSE_CODE(404),
340 COAP_RESPONSE_CODE_NOT_ALLOWED = COAP_RESPONSE_CODE(405),
341 COAP_RESPONSE_CODE_NOT_ACCEPTABLE = COAP_RESPONSE_CODE(406),
342 COAP_RESPONSE_CODE_INCOMPLETE = COAP_RESPONSE_CODE(408),
343 COAP_RESPONSE_CODE_CONFLICT = COAP_RESPONSE_CODE(409),
344 COAP_RESPONSE_CODE_PRECONDITION_FAILED = COAP_RESPONSE_CODE(412),
345 COAP_RESPONSE_CODE_REQUEST_TOO_LARGE = COAP_RESPONSE_CODE(413),
346 COAP_RESPONSE_CODE_UNSUPPORTED_CONTENT_FORMAT = COAP_RESPONSE_CODE(415),
347 COAP_RESPONSE_CODE_UNPROCESSABLE = COAP_RESPONSE_CODE(422),
348 COAP_RESPONSE_CODE_TOO_MANY_REQUESTS = COAP_RESPONSE_CODE(429),
349 COAP_RESPONSE_CODE_INTERNAL_ERROR = COAP_RESPONSE_CODE(500),
350 COAP_RESPONSE_CODE_NOT_IMPLEMENTED = COAP_RESPONSE_CODE(501),
351 COAP_RESPONSE_CODE_BAD_GATEWAY = COAP_RESPONSE_CODE(502),
352 COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE = COAP_RESPONSE_CODE(503),
353 COAP_RESPONSE_CODE_GATEWAY_TIMEOUT = COAP_RESPONSE_CODE(504),
354 COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED = COAP_RESPONSE_CODE(505),
355 COAP_RESPONSE_CODE_HOP_LIMIT_REACHED = COAP_RESPONSE_CODE(508),
356
357 COAP_SIGNALING_CODE_CSM = COAP_SIGNALING_CSM,
358 COAP_SIGNALING_CODE_PING = COAP_SIGNALING_PING,
359 COAP_SIGNALING_CODE_PONG = COAP_SIGNALING_PONG,
360 COAP_SIGNALING_CODE_RELEASE = COAP_SIGNALING_RELEASE,
361 COAP_SIGNALING_CODE_ABORT = COAP_SIGNALING_ABORT
362} coap_pdu_code_t;
363
378 coap_pdu_t *coap_pdu_init(coap_pdu_type_t type, coap_pdu_code_t code,
379 coap_mid_t mid, size_t size);
380
391 coap_pdu_t *coap_new_pdu(coap_pdu_type_t type, coap_pdu_code_t code,
392 coap_session_t *session);
393
402 void coap_delete_pdu(coap_pdu_t *pdu);
403
417 coap_pdu_t *coap_pdu_duplicate(const coap_pdu_t *old_pdu,
418 coap_session_t *session,
419 size_t token_length,
420 const uint8_t *token,
421 coap_opt_filter_t *drop_options);
422
437 int coap_pdu_parse(coap_proto_t proto,
438 const uint8_t *data,
439 size_t length,
440 coap_pdu_t *pdu);
441
456 int coap_add_token(coap_pdu_t *pdu,
457 size_t len,
458 const uint8_t *data);
459
481 size_t coap_add_option(coap_pdu_t *pdu,
482 coap_option_num_t number,
483 size_t len,
484 const uint8_t *data);
485
497 int coap_add_data(coap_pdu_t *pdu,
498 size_t len,
499 const uint8_t *data);
500
513uint8_t *coap_add_data_after(coap_pdu_t *pdu, size_t len);
514
527 int coap_get_data(const coap_pdu_t *pdu,
528 size_t *len,
529 const uint8_t **data);
530
548 int coap_get_data_large(const coap_pdu_t *pdu,
549 size_t *len,
550 const uint8_t **data,
551 size_t *offset,
552 size_t *total);
553
561 coap_pdu_code_t coap_pdu_get_code(const coap_pdu_t *pdu);
562
569 void coap_pdu_set_code(coap_pdu_t *pdu, coap_pdu_code_t code);
570
578 coap_pdu_type_t coap_pdu_get_type(const coap_pdu_t *pdu);
579
586 void coap_pdu_set_type(coap_pdu_t *pdu, coap_pdu_type_t type);
587
595 coap_bin_const_t coap_pdu_get_token(const coap_pdu_t *pdu);
596
604 coap_mid_t coap_pdu_get_mid(const coap_pdu_t *pdu);
605
613 void coap_pdu_set_mid(coap_pdu_t *pdu, coap_mid_t mid);
614
617#endif /* COAP_PDU_H_ */
coap_option.h
Helpers for handling options in CoAP PDUs.
coap_option_num_t
uint16_t coap_option_num_t
Definition: coap_option.h:20
coap_uri.h
Helper functions for URI treatment.
coap_pdu_get_code
coap_pdu_code_t coap_pdu_get_code(const coap_pdu_t *pdu)
Gets the PDU code associated with pdu.
Definition: coap_pdu.c:1494
coap_response_phrase
const char * coap_response_phrase(unsigned char code)
Returns a human-readable response phrase for the specified CoAP response code.
Definition: coap_pdu.c:872
coap_add_data_after
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.
Definition: coap_pdu.c:778
coap_delete_pdu
void coap_delete_pdu(coap_pdu_t *pdu)
Dispose of an CoAP PDU and frees associated storage.
Definition: coap_pdu.c:163
coap_pdu_set_code
void coap_pdu_set_code(coap_pdu_t *pdu, coap_pdu_code_t code)
Sets the PDU code in the pdu.
Definition: coap_pdu.c:1499
coap_mid_t
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
Definition: coap_pdu.h:255
coap_request_t
coap_request_t
CoAP PDU Request methods.
Definition: coap_pdu.h:74
COAP_RESPONSE_CODE
#define COAP_RESPONSE_CODE(N)
Definition: coap_pdu.h:152
COAP_SIGNALING_CODE
#define COAP_SIGNALING_CODE(N)
Definition: coap_pdu.h:178
coap_proto_t
coap_proto_t
CoAP protocol types.
Definition: coap_pdu.h:304
coap_new_pdu
coap_pdu_t * coap_new_pdu(coap_pdu_type_t type, coap_pdu_code_t code, coap_session_t *session)
Creates a new CoAP PDU.
Definition: coap_pdu.c:153
coap_pdu_code_t
coap_pdu_code_t
Set of codes available for a PDU.
Definition: coap_pdu.h:318
coap_pdu_type_t
coap_pdu_type_t
CoAP PDU message type definitions.
Definition: coap_pdu.h:64
coap_add_token
int coap_add_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds token of length len to pdu.
Definition: coap_pdu.c:304
coap_pdu_set_type
void coap_pdu_set_type(coap_pdu_t *pdu, coap_pdu_type_t type)
Sets the PDU type in the pdu.
Definition: coap_pdu.c:1510
coap_add_option
size_t coap_add_option(coap_pdu_t *pdu, coap_option_num_t number, size_t len, const uint8_t *data)
Adds option of given number to pdu that is passed as first parameter.
Definition: coap_pdu.c:691
coap_pdu_signaling_proto_t
coap_pdu_signaling_proto_t
Definition: coap_pdu.h:180
coap_pdu_get_type
coap_pdu_type_t coap_pdu_get_type(const coap_pdu_t *pdu)
Gets the PDU type associated with pdu.
Definition: coap_pdu.c:1505
coap_get_data
int coap_get_data(const coap_pdu_t *pdu, size_t *len, const uint8_t **data)
Retrieves the length and data pointer of specified PDU.
Definition: coap_pdu.c:797
coap_pdu_parse
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: coap_pdu.c:1382
coap_pdu_set_mid
void coap_pdu_set_mid(coap_pdu_t *pdu, coap_mid_t mid)
Sets the message id in the pdu.
Definition: coap_pdu.c:1526
coap_pdu_duplicate
coap_pdu_t * coap_pdu_duplicate(const coap_pdu_t *old_pdu, coap_session_t *session, size_t token_length, const uint8_t *token, coap_opt_filter_t *drop_options)
Duplicate an existing PDU.
Definition: coap_pdu.c:179
coap_pdu_init
coap_pdu_t * coap_pdu_init(coap_pdu_type_t type, coap_pdu_code_t code, coap_mid_t mid, size_t size)
Creates a new CoAP PDU with at least enough storage space for the given size maximum message size.
Definition: coap_pdu.c:97
coap_get_data_large
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: coap_pdu.c:805
coap_pdu_get_mid
coap_mid_t coap_pdu_get_mid(const coap_pdu_t *pdu)
Gets the message id associated with pdu.
Definition: coap_pdu.c:1521
coap_add_data
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: coap_pdu.c:766
coap_pdu_get_token
coap_bin_const_t coap_pdu_get_token(const coap_pdu_t *pdu)
Gets the token associated with pdu.
Definition: coap_pdu.c:1516
COAP_REQUEST_PUT
@ COAP_REQUEST_PUT
Definition: coap_pdu.h:77
COAP_REQUEST_DELETE
@ COAP_REQUEST_DELETE
Definition: coap_pdu.h:78
COAP_REQUEST_GET
@ COAP_REQUEST_GET
Definition: coap_pdu.h:75
COAP_REQUEST_FETCH
@ COAP_REQUEST_FETCH
Definition: coap_pdu.h:79
COAP_REQUEST_PATCH
@ COAP_REQUEST_PATCH
Definition: coap_pdu.h:80
COAP_REQUEST_IPATCH
@ COAP_REQUEST_IPATCH
Definition: coap_pdu.h:81
COAP_REQUEST_POST
@ COAP_REQUEST_POST
Definition: coap_pdu.h:76
COAP_PROTO_WS
@ COAP_PROTO_WS
Definition: coap_pdu.h:310
COAP_PROTO_DTLS
@ COAP_PROTO_DTLS
Definition: coap_pdu.h:307
COAP_PROTO_UDP
@ COAP_PROTO_UDP
Definition: coap_pdu.h:306
COAP_PROTO_NONE
@ COAP_PROTO_NONE
Definition: coap_pdu.h:305
COAP_PROTO_TLS
@ COAP_PROTO_TLS
Definition: coap_pdu.h:309
COAP_PROTO_WSS
@ COAP_PROTO_WSS
Definition: coap_pdu.h:311
COAP_PROTO_TCP
@ COAP_PROTO_TCP
Definition: coap_pdu.h:308
COAP_PROTO_LAST
@ COAP_PROTO_LAST
Definition: coap_pdu.h:312
COAP_RESPONSE_CODE_INTERNAL_ERROR
@ COAP_RESPONSE_CODE_INTERNAL_ERROR
Definition: coap_pdu.h:349
COAP_RESPONSE_CODE_HOP_LIMIT_REACHED
@ COAP_RESPONSE_CODE_HOP_LIMIT_REACHED
Definition: coap_pdu.h:355
COAP_SIGNALING_CODE_ABORT
@ COAP_SIGNALING_CODE_ABORT
Definition: coap_pdu.h:361
COAP_RESPONSE_CODE_PRECONDITION_FAILED
@ COAP_RESPONSE_CODE_PRECONDITION_FAILED
Definition: coap_pdu.h:344
COAP_RESPONSE_CODE_NOT_ALLOWED
@ COAP_RESPONSE_CODE_NOT_ALLOWED
Definition: coap_pdu.h:340
COAP_RESPONSE_CODE_CHANGED
@ COAP_RESPONSE_CODE_CHANGED
Definition: coap_pdu.h:332
COAP_REQUEST_CODE_PUT
@ COAP_REQUEST_CODE_PUT
Definition: coap_pdu.h:323
COAP_REQUEST_CODE_POST
@ COAP_REQUEST_CODE_POST
Definition: coap_pdu.h:322
COAP_RESPONSE_CODE_NOT_ACCEPTABLE
@ COAP_RESPONSE_CODE_NOT_ACCEPTABLE
Definition: coap_pdu.h:341
COAP_SIGNALING_CODE_CSM
@ COAP_SIGNALING_CODE_CSM
Definition: coap_pdu.h:357
COAP_REQUEST_CODE_PATCH
@ COAP_REQUEST_CODE_PATCH
Definition: coap_pdu.h:326
COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED
@ COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED
Definition: coap_pdu.h:354
COAP_RESPONSE_CODE_BAD_REQUEST
@ COAP_RESPONSE_CODE_BAD_REQUEST
Definition: coap_pdu.h:335
COAP_SIGNALING_CODE_PING
@ COAP_SIGNALING_CODE_PING
Definition: coap_pdu.h:358
COAP_RESPONSE_CODE_INCOMPLETE
@ COAP_RESPONSE_CODE_INCOMPLETE
Definition: coap_pdu.h:342
COAP_REQUEST_CODE_DELETE
@ COAP_REQUEST_CODE_DELETE
Definition: coap_pdu.h:324
COAP_SIGNALING_CODE_PONG
@ COAP_SIGNALING_CODE_PONG
Definition: coap_pdu.h:359
COAP_RESPONSE_CODE_NOT_IMPLEMENTED
@ COAP_RESPONSE_CODE_NOT_IMPLEMENTED
Definition: coap_pdu.h:350
COAP_RESPONSE_CODE_NOT_FOUND
@ COAP_RESPONSE_CODE_NOT_FOUND
Definition: coap_pdu.h:339
COAP_RESPONSE_CODE_BAD_GATEWAY
@ COAP_RESPONSE_CODE_BAD_GATEWAY
Definition: coap_pdu.h:351
COAP_RESPONSE_CODE_BAD_OPTION
@ COAP_RESPONSE_CODE_BAD_OPTION
Definition: coap_pdu.h:337
COAP_RESPONSE_CODE_REQUEST_TOO_LARGE
@ COAP_RESPONSE_CODE_REQUEST_TOO_LARGE
Definition: coap_pdu.h:345
COAP_RESPONSE_CODE_TOO_MANY_REQUESTS
@ COAP_RESPONSE_CODE_TOO_MANY_REQUESTS
Definition: coap_pdu.h:348
COAP_RESPONSE_CODE_CONFLICT
@ COAP_RESPONSE_CODE_CONFLICT
Definition: coap_pdu.h:343
COAP_RESPONSE_CODE_DELETED
@ COAP_RESPONSE_CODE_DELETED
Definition: coap_pdu.h:330
COAP_RESPONSE_CODE_UNAUTHORIZED
@ COAP_RESPONSE_CODE_UNAUTHORIZED
Definition: coap_pdu.h:336
COAP_RESPONSE_CODE_CREATED
@ COAP_RESPONSE_CODE_CREATED
Definition: coap_pdu.h:329
COAP_EMPTY_CODE
@ COAP_EMPTY_CODE
Definition: coap_pdu.h:319
COAP_RESPONSE_CODE_CONTENT
@ COAP_RESPONSE_CODE_CONTENT
Definition: coap_pdu.h:333
COAP_RESPONSE_CODE_UNPROCESSABLE
@ COAP_RESPONSE_CODE_UNPROCESSABLE
Definition: coap_pdu.h:347
COAP_RESPONSE_CODE_CONTINUE
@ COAP_RESPONSE_CODE_CONTINUE
Definition: coap_pdu.h:334
COAP_RESPONSE_CODE_VALID
@ COAP_RESPONSE_CODE_VALID
Definition: coap_pdu.h:331
COAP_RESPONSE_CODE_UNSUPPORTED_CONTENT_FORMAT
@ COAP_RESPONSE_CODE_UNSUPPORTED_CONTENT_FORMAT
Definition: coap_pdu.h:346
COAP_REQUEST_CODE_GET
@ COAP_REQUEST_CODE_GET
Definition: coap_pdu.h:321
COAP_SIGNALING_CODE_RELEASE
@ COAP_SIGNALING_CODE_RELEASE
Definition: coap_pdu.h:360
COAP_REQUEST_CODE_FETCH
@ COAP_REQUEST_CODE_FETCH
Definition: coap_pdu.h:325
COAP_RESPONSE_CODE_GATEWAY_TIMEOUT
@ COAP_RESPONSE_CODE_GATEWAY_TIMEOUT
Definition: coap_pdu.h:353
COAP_REQUEST_CODE_IPATCH
@ COAP_REQUEST_CODE_IPATCH
Definition: coap_pdu.h:327
COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE
@ COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE
Definition: coap_pdu.h:352
COAP_RESPONSE_CODE_FORBIDDEN
@ COAP_RESPONSE_CODE_FORBIDDEN
Definition: coap_pdu.h:338
COAP_MESSAGE_NON
@ COAP_MESSAGE_NON
Definition: coap_pdu.h:66
COAP_MESSAGE_ACK
@ COAP_MESSAGE_ACK
Definition: coap_pdu.h:67
COAP_MESSAGE_CON
@ COAP_MESSAGE_CON
Definition: coap_pdu.h:65
COAP_MESSAGE_RST
@ COAP_MESSAGE_RST
Definition: coap_pdu.h:68
COAP_SIGNALING_RELEASE
@ COAP_SIGNALING_RELEASE
Definition: coap_pdu.h:184
COAP_SIGNALING_CSM
@ COAP_SIGNALING_CSM
Definition: coap_pdu.h:181
COAP_SIGNALING_PONG
@ COAP_SIGNALING_PONG
Definition: coap_pdu.h:183
COAP_SIGNALING_PING
@ COAP_SIGNALING_PING
Definition: coap_pdu.h:182
COAP_SIGNALING_ABORT
@ COAP_SIGNALING_ABORT
Definition: coap_pdu.h:185
COAP_DEPRECATED
#define COAP_DEPRECATED
Definition: libcoap.h:61
coap_bin_const_t
CoAP binary data definition with const data.
Definition: coap_str.h:64
coap_opt_filter_t
Definition: coap_option.h:101
coap_option
Definition: coap_pdu.h:273
coap_option::length
unsigned int length
Definition: coap_pdu.h:275
coap_option::key
uint16_t key
Definition: coap_pdu.h:274
coap_pdu_t
structure for CoAP PDUs
Definition: coap_pdu_internal.h:119
coap_session_t
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
Definition: coap_session_internal.h:68