libcoap 4.3.5-develop-ea01661
Loading...
Searching...
No Matches
coap_pdu_internal.h
Go to the documentation of this file.
1/*
2 * coap_pdu_internal.h -- CoAP PDU structure
3 *
4 * Copyright (C) 2010-2025 Olaf Bergmann <bergmann@tzi.org>
5 *
6 * SPDX-License-Identifier: BSD-2-Clause
7 *
8 * This file is part of the CoAP library libcoap. Please see README for terms
9 * of use.
10 */
11
17#ifndef COAP_COAP_PDU_INTERNAL_H_
18#define COAP_COAP_PDU_INTERNAL_H_
19
20#include "coap_internal.h"
21
22#ifdef WITH_LWIP
23#include <lwip/pbuf.h>
24#endif
25
26#ifdef RIOT_VERSION
27#include <limits.h>
28#endif /* RIOT_VERSION */
29
30#ifdef HAVE_LIMITS_H
31#include <limits.h>
32#endif /* HAVE_LIMITS_H */
33
34#include <stdint.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
47#define COAP_DEFAULT_VERSION 1 /* version of CoAP supported */
48
49/* TCP Message format constants, do not modify */
50#define COAP_MESSAGE_SIZE_OFFSET_TCP8 13
51#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
52#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
53
54/* Derived message size limits */
55#define COAP_MAX_MESSAGE_SIZE_TCP0 (COAP_MESSAGE_SIZE_OFFSET_TCP8-1) /* 12 */
56#define COAP_MAX_MESSAGE_SIZE_TCP8 (COAP_MESSAGE_SIZE_OFFSET_TCP16-1) /* 268 */
57#define COAP_MAX_MESSAGE_SIZE_TCP16 (COAP_MESSAGE_SIZE_OFFSET_TCP32-1) /* 65804 */
58#define COAP_MAX_MESSAGE_SIZE_TCP32 (COAP_MESSAGE_SIZE_OFFSET_TCP32+0xFFFFFFFF)
59#if COAP_OSCORE_SUPPORT
60/* for oscore encryption */
61#define COAP_MAX_CHUNK_SIZE COAP_DEFAULT_MAX_PDU_RX_SIZE
62#define OSCORE_CRYPTO_BUFFER_SIZE (COAP_MAX_CHUNK_SIZE+16)
63#endif /* COAP_OSCORE_SUPPORT */
64
65/* Extended Token constants */
66#define COAP_TOKEN_EXT_1B_TKL 13
67#define COAP_TOKEN_EXT_2B_TKL 14
68#define COAP_TOKEN_EXT_1B_BIAS 13
69#define COAP_TOKEN_EXT_2B_BIAS 269 /* 13 + 256 */
70
71#ifndef COAP_DEBUG_BUF_SIZE
72#if defined(WITH_CONTIKI) || defined(WITH_LWIP)
73#define COAP_DEBUG_BUF_SIZE 128
74#else /* defined(WITH_CONTIKI) || defined(WITH_LWIP) */
75/* 1024 derived from RFC7252 4.6. Message Size max payload */
76#define COAP_DEBUG_BUF_SIZE (8 + 1024 * 2)
77#endif /* defined(WITH_CONTIKI) || defined(WITH_LWIP) */
78#endif /* COAP_DEBUG_BUF_SIZE */
79
80#ifndef COAP_DEFAULT_MAX_PDU_RX_SIZE
81#if defined(WITH_LWIP)
82#define COAP_DEFAULT_MAX_PDU_RX_SIZE (COAP_MAX_MESSAGE_SIZE_TCP16+6UL)
83#elif defined(WITH_CONTIKI)
84#define COAP_DEFAULT_MAX_PDU_RX_SIZE (UIP_APPDATA_SIZE)
85#elif (UINT_MAX < (8UL*1024*1024+256))
86#define COAP_DEFAULT_MAX_PDU_RX_SIZE (1500UL)
87#elif defined(RIOT_VERSION) && defined(COAP_DISABLE_TCP)
88#define COAP_DEFAULT_MAX_PDU_RX_SIZE (1500UL)
89#else
90/* 8 MiB max-message-size plus some space for options */
91#define COAP_DEFAULT_MAX_PDU_RX_SIZE (8UL*1024*1024+256)
92#endif
93#endif /* COAP_DEFAULT_MAX_PDU_RX_SIZE */
94
99#define COAP_DROPPED_RESPONSE -2
100
101#define COAP_PDU_DELAYED -3
102
103#define COAP_PAYLOAD_START 0xFF /* payload marker */
104
105#define COAP_PDU_IS_EMPTY(pdu) ((pdu)->code == 0)
106#define COAP_PDU_IS_REQUEST(pdu) (!COAP_PDU_IS_EMPTY(pdu) && (pdu)->code < 32)
107/* Code 1.xx (32-63) and 6.xx (192-224) currently invalid */
108#define COAP_PDU_IS_RESPONSE(pdu) ((pdu)->code >= 64 && (pdu)->code < 192)
109#define COAP_PDU_IS_SIGNALING(pdu) ((pdu)->code >= 224)
110#define COAP_PDU_IS_PING(pdu) ((COAP_PDU_IS_EMPTY(pdu) && \
111 ((pdu)->type == COAP_MESSAGE_CON)) || \
112 ((pdu)->code == COAP_SIGNALING_CODE_PING))
113
114#define COAP_PDU_MAX_UDP_HEADER_SIZE 4
115#define COAP_PDU_MAX_TCP_HEADER_SIZE 6
116
183
200 const uint8_t *data,
201 size_t length,
202 coap_pdu_t *pdu,
203 coap_opt_filter_t *error_opts);
204
214int coap_pdu_resize(coap_pdu_t *pdu, size_t new_size);
215
225int coap_pdu_check_resize(coap_pdu_t *pdu, size_t new_size);
226
237 const uint8_t *data);
238
251 const uint8_t *data,
252 size_t length);
253
262
275int coap_pdu_parse_opt(coap_pdu_t *pdu, coap_opt_filter_t *error_opts);
276
286void coap_pdu_clear(coap_pdu_t *pdu, size_t size);
287
309 coap_option_num_t number,
310 size_t len,
311 const uint8_t *data);
321
335 size_t len, const uint8_t *data);
336
349 coap_option_num_t number,
350 size_t len,
351 const uint8_t *data);
352
363
375 size_t len,
376 const uint8_t *data);
377
387
401 coap_session_t *session);
402
419
424
441 coap_session_t *session,
442 size_t token_length,
443 const uint8_t *token,
444 coap_opt_filter_t *drop_options);
445
460
477
480#ifdef __cplusplus
481}
482#endif
483
484#endif /* COAP_COAP_PDU_INTERNAL_H_ */
Pulls together all the internal only header files.
uint16_t coap_option_num_t
Definition coap_option.h:24
coap_pdu_t * coap_pdu_reference_lkd(coap_pdu_t *pdu)
Increment reference counter on a pdu to stop it prematurely getting freed off when coap_delete_pdu() ...
Definition coap_pdu.c:1655
void coap_delete_pdu_lkd(coap_pdu_t *pdu)
Dispose of an CoAP PDU and free off associated storage.
Definition coap_pdu.c:194
size_t coap_insert_option(coap_pdu_t *pdu, coap_option_num_t number, size_t len, const uint8_t *data)
Inserts option of given number in the pdu with the appropriate data.
Definition coap_pdu.c:633
int coap_remove_option(coap_pdu_t *pdu, coap_option_num_t number)
Removes (first) option of given number from the pdu.
Definition coap_pdu.c:493
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 coap_pdu.c:417
int coap_pdu_parse_opt(coap_pdu_t *pdu, coap_opt_filter_t *error_opts)
Verify consistency in the given CoAP PDU structure and locate the data.
Definition coap_pdu.c:1352
int coap_pdu_parse_header(coap_pdu_t *pdu, coap_proto_t proto)
Decode the protocol specific header for the specified PDU.
Definition coap_pdu.c:1078
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 coap_pdu.c:994
coap_pdu_t * coap_new_pdu_lkd(coap_pdu_type_t type, coap_pdu_code_t code, coap_session_t *session)
Creates a new CoAP PDU.
Definition coap_pdu.c:173
int coap_option_check_repeatable(coap_option_num_t number)
Check whether the option is allowed to be repeated or not.
Definition coap_pdu.c:587
void coap_pdu_clear(coap_pdu_t *pdu, size_t size)
Clears any contents from pdu and resets used_size, and data pointers.
Definition coap_pdu.c:45
size_t coap_update_option(coap_pdu_t *pdu, coap_option_num_t number, size_t len, const uint8_t *data)
Updates existing first option of given number in the pdu with the new data.
Definition coap_pdu.c:727
size_t coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto)
Compose the protocol specific header for the specified PDU.
Definition coap_pdu.c:1517
coap_pdu_t * coap_pdu_duplicate_lkd(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:234
int coap_pdu_parse2(coap_proto_t proto, const uint8_t *data, size_t length, coap_pdu_t *pdu, coap_opt_filter_t *error_opts)
Parses data into the CoAP PDU structure given in result.
Definition coap_pdu.c:1493
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 coap_pdu.c:343
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 coap_pdu.c:1025
coap_pdu_t * coap_const_pdu_reference_lkd(const coap_pdu_t *pdu)
Increment reference counter on a const pdu to stop it prematurely getting freed off when coap_delete_...
Definition coap_pdu.c:1663
int coap_pdu_resize(coap_pdu_t *pdu, size_t new_size)
Dynamically grows the size of pdu to new_size.
Definition coap_pdu.c:301
COAP_STATIC_INLINE void coap_pdu_release_lkd(coap_pdu_t *pdu)
size_t coap_add_option_internal(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:783
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
Definition coap_pdu.h:268
coap_proto_t
CoAP protocol types.
Definition coap_pdu.h:317
coap_pdu_code_t
Set of codes available for a PDU.
Definition coap_pdu.h:331
coap_pdu_type_t
CoAP PDU message type definitions.
Definition coap_pdu.h:72
#define COAP_STATIC_INLINE
Definition libcoap.h:57
CoAP binary data definition with const data.
Definition coap_str.h:67
CoAP binary data definition.
Definition coap_str.h:59
Structure to hold large body (many blocks) transmission information.
structure for CoAP PDUs
uint8_t max_hdr_size
space reserved for protocol-specific header
uint16_t max_opt
highest option number in PDU
uint8_t * token
first byte of token (or extended length bytes prefix), if any, or options
coap_lg_xmit_t * lg_xmit
Holds ptr to lg_xmit if sending a set of blocks.
size_t body_length
Holds body data length.
size_t max_size
maximum size for token, options and payload, or zero for variable size pdu
const uint8_t * body_data
Holds ptr to re-assembled data or NULL.
size_t body_offset
Holds body data offset.
unsigned ref
reference count
coap_pdu_code_t code
request method (value 1–31) or response code (value 64-255)
uint8_t hdr_size
actual size used for protocol-specific header (0 until header is encoded)
coap_bin_const_t actual_token
Actual token in pdu.
uint8_t * data
first byte of payload, if any
coap_mid_t mid
message id, if any, in regular host byte order
uint32_t e_token_length
length of Token space (includes leading extended bytes
size_t used_size
used bytes of storage for token, options and payload
uint8_t crit_opt
Set if unknown critical option for proxy.
coap_binary_t * data_free
Data to be freed off by coap_delete_pdu()
size_t alloc_size
allocated storage for token, options and payload
coap_session_t * session
Session responsible for PDU or NULL.
size_t body_total
Holds body data total size.
coap_pdu_type_t type
message type
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...