libcoap  4.3.0rc1
pdu.h File Reference

Pre-defined constants that reflect defaults for CoAP. More...

#include "uri.h"
#include "option.h"
#include <stdint.h>
+ Include dependency graph for pdu.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  coap_option
 
struct  coap_pdu_t
 structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload marker (0xff), then the payload if stored inline. More...
 

Macros

#define COAP_DEFAULT_PORT   5683 /* CoAP default UDP/TCP port */
 
#define COAPS_DEFAULT_PORT   5684 /* CoAP default UDP/TCP port for secure transmission */
 
#define COAP_DEFAULT_MAX_AGE   60 /* default maximum object lifetime in seconds */
 
#define COAP_DEFAULT_MTU   1152
 
#define COAP_DEFAULT_HOP_LIMIT   16
 
#define COAP_MESSAGE_SIZE_OFFSET_TCP8   13
 
#define COAP_MESSAGE_SIZE_OFFSET_TCP16   269 /* 13 + 256 */
 
#define COAP_MESSAGE_SIZE_OFFSET_TCP32   65805 /* 269 + 65536 */
 
#define COAP_MAX_MESSAGE_SIZE_TCP0   (COAP_MESSAGE_SIZE_OFFSET_TCP8-1) /* 12 */
 
#define COAP_MAX_MESSAGE_SIZE_TCP8   (COAP_MESSAGE_SIZE_OFFSET_TCP16-1) /* 268 */
 
#define COAP_MAX_MESSAGE_SIZE_TCP16   (COAP_MESSAGE_SIZE_OFFSET_TCP32-1) /* 65804 */
 
#define COAP_MAX_MESSAGE_SIZE_TCP32   (COAP_MESSAGE_SIZE_OFFSET_TCP32+0xFFFFFFFF)
 
#define COAP_DEFAULT_MAX_PDU_RX_SIZE   (8UL*1024*1024+256)
 
#define COAP_DEBUG_BUF_SIZE   (8 + 1024 * 2)
 
#define COAP_DEFAULT_VERSION   1 /* version of CoAP supported */
 
#define COAP_DEFAULT_SCHEME   "coap" /* the default scheme for CoAP URIs */
 
#define COAP_DEFAULT_URI_WELLKNOWN   ".well-known/core"
 well-known resources URI More...
 
#define COAP_MESSAGE_CON   0 /* confirmable message (requires ACK/RST) */
 
#define COAP_MESSAGE_NON   1 /* non-confirmable message (one-shot message) */
 
#define COAP_MESSAGE_ACK   2 /* used to acknowledge confirmable messages */
 
#define COAP_MESSAGE_RST   3 /* indicates error in received messages */
 
#define COAP_OPTION_IF_MATCH   1 /* C__RE__, opaque, 0-8 B, RFC7252 */
 
#define COAP_OPTION_URI_HOST   3 /* CU-___U, String, 1-255 B, RFC7252 */
 
#define COAP_OPTION_ETAG   4 /* ___RE__, opaque, 1-8 B, RFC7252 */
 
#define COAP_OPTION_IF_NONE_MATCH   5 /* C___E__, empty, 0 B, RFC7252 */
 
#define COAP_OPTION_OBSERVE   6 /* _U-_E_U, empty/uint,0/0-3 B, RFC7641 */
 
#define COAP_OPTION_URI_PORT   7 /* CU-___U, uint, 0-2 B, RFC7252 */
 
#define COAP_OPTION_LOCATION_PATH   8 /* ___RE__, String, 0-255 B, RFC7252 */
 
#define COAP_OPTION_OSCORE   9 /* C_____U, *, 0-255 B, RFC8613 */
 
#define COAP_OPTION_URI_PATH   11 /* CU-RE__, String, 0-255 B, RFC7252 */
 
#define COAP_OPTION_CONTENT_FORMAT   12 /* ____E__, uint, 0-2 B, RFC7252 */
 
#define COAP_OPTION_CONTENT_TYPE   COAP_OPTION_CONTENT_FORMAT
 
#define COAP_OPTION_MAXAGE   14 /* _U-_E_U, uint, 0-4 B, RFC7252 */
 
#define COAP_OPTION_URI_QUERY   15 /* CU-RE__, String, 1-255 B, RFC7252 */
 
#define COAP_OPTION_HOP_LIMIT   16 /* ______U, uint, 1 B, RFC8768 */
 
#define COAP_OPTION_ACCEPT   17 /* C___E__, uint, 0-2 B, RFC7252 */
 
#define COAP_OPTION_LOCATION_QUERY   20 /* ___RE__, String, 0-255 B, RFC7252 */
 
#define COAP_OPTION_BLOCK2   23 /* CU-_E_U, uint, 0-3 B, RFC7959 */
 
#define COAP_OPTION_BLOCK1   27 /* CU-_E_U, uint, 0-3 B, RFC7959 */
 
#define COAP_OPTION_SIZE2   28 /* __N_E_U, uint, 0-4 B, RFC7959 */
 
#define COAP_OPTION_PROXY_URI   35 /* CU-___U, String, 1-1034 B, RFC7252 */
 
#define COAP_OPTION_PROXY_SCHEME   39 /* CU-___U, String, 1-255 B, RFC7252 */
 
#define COAP_OPTION_SIZE1   60 /* __N_E_U, uint, 0-4 B, RFC7252 */
 
#define COAP_OPTION_NORESPONSE   258 /* _U-_E_U, uint, 0-1 B, RFC7967 */
 
#define COAP_MAX_OPT   65535
 the highest option number we know More...
 
#define COAP_RESPONSE_CODE(N)   (((N)/100 << 5) | (N)%100)
 
#define COAP_RESPONSE_CLASS(C)   (((C) >> 5) & 0xFF)
 
#define COAP_ERROR_PHRASE_LENGTH   32
 maximum length of error phrase More...
 
#define COAP_SIGNALING_CODE(N)   (((N)/100 << 5) | (N)%100)
 
#define COAP_SIGNALING_CSM   COAP_SIGNALING_CODE(701)
 
#define COAP_SIGNALING_PING   COAP_SIGNALING_CODE(702)
 
#define COAP_SIGNALING_PONG   COAP_SIGNALING_CODE(703)
 
#define COAP_SIGNALING_RELEASE   COAP_SIGNALING_CODE(704)
 
#define COAP_SIGNALING_ABORT   COAP_SIGNALING_CODE(705)
 
#define COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE   2
 
#define COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER   4
 
#define COAP_SIGNALING_OPTION_CUSTODY   2
 
#define COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS   2
 
#define COAP_SIGNALING_OPTION_HOLD_OFF   4
 
#define COAP_SIGNALING_OPTION_BAD_CSM_OPTION   2
 
#define COAP_MEDIATYPE_TEXT_PLAIN   0 /* text/plain (UTF-8) */
 
#define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT   40 /* application/link-format */
 
#define COAP_MEDIATYPE_APPLICATION_XML   41 /* application/xml */
 
#define COAP_MEDIATYPE_APPLICATION_OCTET_STREAM   42 /* application/octet-stream */
 
#define COAP_MEDIATYPE_APPLICATION_RDF_XML   43 /* application/rdf+xml */
 
#define COAP_MEDIATYPE_APPLICATION_EXI   47 /* application/exi */
 
#define COAP_MEDIATYPE_APPLICATION_JSON   50 /* application/json */
 
#define COAP_MEDIATYPE_APPLICATION_CBOR   60 /* application/cbor */
 
#define COAP_MEDIATYPE_APPLICATION_CWT   61 /* application/cwt, RFC 8392 */
 
#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN   98 /* application/cose; cose-type="cose-sign" */
 
#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN1   18 /* application/cose; cose-type="cose-sign1" */
 
#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT   96 /* application/cose; cose-type="cose-encrypt" */
 
#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0   16 /* application/cose; cose-type="cose-encrypt0" */
 
#define COAP_MEDIATYPE_APPLICATION_COSE_MAC   97 /* application/cose; cose-type="cose-mac" */
 
#define COAP_MEDIATYPE_APPLICATION_COSE_MAC0   17 /* application/cose; cose-type="cose-mac0" */
 
#define COAP_MEDIATYPE_APPLICATION_COSE_KEY   101 /* application/cose-key */
 
#define COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET   102 /* application/cose-key-set */
 
#define COAP_MEDIATYPE_APPLICATION_SENML_JSON   110 /* application/senml+json */
 
#define COAP_MEDIATYPE_APPLICATION_SENSML_JSON   111 /* application/sensml+json */
 
#define COAP_MEDIATYPE_APPLICATION_SENML_CBOR   112 /* application/senml+cbor */
 
#define COAP_MEDIATYPE_APPLICATION_SENSML_CBOR   113 /* application/sensml+cbor */
 
#define COAP_MEDIATYPE_APPLICATION_SENML_EXI   114 /* application/senml-exi */
 
#define COAP_MEDIATYPE_APPLICATION_SENSML_EXI   115 /* application/sensml-exi */
 
#define COAP_MEDIATYPE_APPLICATION_SENML_XML   310 /* application/senml+xml */
 
#define COAP_MEDIATYPE_APPLICATION_SENSML_XML   311 /* application/sensml+xml */
 
#define COAP_MEDIATYPE_APPLICATION_DOTS_CBOR   271 /* application/dots+cbor */
 
#define COAP_MEDIATYPE_ANY   0xff /* any media type */
 
#define COAP_INVALID_MID   -1
 Indicates an invalid message id. More...
 
#define COAP_DROPPED_RESPONSE   -2
 Indicates that a response is suppressed. More...
 
#define COAP_PDU_DELAYED   -3
 
#define COAP_PAYLOAD_START   0xFF /* payload marker */
 
#define COAP_OPTION_KEY(option)   (option).key
 
#define COAP_OPTION_LENGTH(option)   (option).length
 
#define COAP_OPTION_DATA(option)   ((unsigned char *)&(option) + sizeof(coap_option))
 
#define COAP_PDU_IS_EMPTY(pdu)   ((pdu)->code == 0)
 
#define COAP_PDU_IS_REQUEST(pdu)   (!COAP_PDU_IS_EMPTY(pdu) && (pdu)->code < 32)
 
#define COAP_PDU_IS_RESPONSE(pdu)   ((pdu)->code >= 64 && (pdu)->code < 224)
 
#define COAP_PDU_IS_SIGNALING(pdu)   ((pdu)->code >= 224)
 
#define COAP_PDU_MAX_UDP_HEADER_SIZE   4
 
#define COAP_PDU_MAX_TCP_HEADER_SIZE   6
 
#define COAP_PROTO_NONE   0
 coap_proto_t values More...
 
#define COAP_PROTO_UDP   1
 
#define COAP_PROTO_DTLS   2
 
#define COAP_PROTO_TCP   3
 
#define COAP_PROTO_TLS   4
 

Typedefs

typedef enum coap_request_t coap_request_t
 
typedef int coap_mid_t
 coap_mid_t is used to store the CoAP Message ID of a CoAP PDU. More...
 
typedef uint8_t coap_proto_t
 

Enumerations

enum  coap_request_t {
  COAP_REQUEST_GET = 1 , COAP_REQUEST_POST , COAP_REQUEST_PUT , COAP_REQUEST_DELETE ,
  COAP_REQUEST_FETCH , COAP_REQUEST_PATCH , COAP_REQUEST_IPATCH
}
 
enum  coap_response_code {
  COAP_RESPONSE_CODE_OK = COAP_RESPONSE_CODE(200) , COAP_RESPONSE_CODE_CREATED = COAP_RESPONSE_CODE(201) , COAP_RESPONSE_CODE_DELETED = COAP_RESPONSE_CODE(202) , COAP_RESPONSE_CODE_VALID = COAP_RESPONSE_CODE(203) ,
  COAP_RESPONSE_CODE_CHANGED = COAP_RESPONSE_CODE(204) , COAP_RESPONSE_CODE_CONTENT = COAP_RESPONSE_CODE(205) , COAP_RESPONSE_CODE_CONTINUE = COAP_RESPONSE_CODE(231) , COAP_RESPONSE_CODE_BAD_REQUEST = COAP_RESPONSE_CODE(400) ,
  COAP_RESPONSE_CODE_UNAUTHORIZED = COAP_RESPONSE_CODE(401) , COAP_RESPONSE_CODE_BAD_OPTION = COAP_RESPONSE_CODE(402) , COAP_RESPONSE_CODE_FORBIDDEN = COAP_RESPONSE_CODE(403) , COAP_RESPONSE_CODE_NOT_FOUND = COAP_RESPONSE_CODE(404) ,
  COAP_RESPONSE_CODE_NOT_ALLOWED = COAP_RESPONSE_CODE(405) , COAP_RESPONSE_CODE_NOT_ACCEPTABLE = COAP_RESPONSE_CODE(406) , COAP_RESPONSE_CODE_INCOMPLETE = COAP_RESPONSE_CODE(408) , COAP_RESPONSE_CODE_CONFLICT = COAP_RESPONSE_CODE(409) ,
  COAP_RESPONSE_CODE_PRECONDITION_FAILED = COAP_RESPONSE_CODE(412) , COAP_RESPONSE_CODE_REQUEST_TOO_LARGE = COAP_RESPONSE_CODE(413) , COAP_RESPONSE_CODE_UNSUPPORTED_CONTENT_FORMAT , COAP_RESPONSE_CODE_UNPROCESSABLE = COAP_RESPONSE_CODE(422) ,
  COAP_RESPONSE_CODE_TOO_MANY_REQUESTS = COAP_RESPONSE_CODE(429) , COAP_RESPONSE_CODE_INTERNAL_ERROR = COAP_RESPONSE_CODE(500) , COAP_RESPONSE_CODE_NOT_IMPLEMENTED = COAP_RESPONSE_CODE(501) , COAP_RESPONSE_CODE_BAD_GATEWAY = COAP_RESPONSE_CODE(502) ,
  COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE = COAP_RESPONSE_CODE(503) , COAP_RESPONSE_CODE_GATEWAY_TIMEOUT = COAP_RESPONSE_CODE(504) , COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED , COAP_RESPONSE_CODE_HOP_LIMIT_REACHED = COAP_RESPONSE_CODE(508)
}
 Set of response codes available for a response packet. More...
 

Functions

const char * coap_response_phrase (unsigned char code)
 Returns a human-readable response phrase for the specified CoAP response code. More...
 
coap_pdu_tcoap_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. More...
 
int coap_pdu_resize (coap_pdu_t *pdu, size_t new_size)
 Dynamically grows the size of pdu to new_size. More...
 
int coap_pdu_check_resize (coap_pdu_t *pdu, size_t new_size)
 Dynamically grows the size of pdu to new_size if needed. More...
 
void coap_pdu_clear (coap_pdu_t *pdu, size_t size)
 Clears any contents from pdu and resets used_size, and data pointers. More...
 
coap_pdu_tcoap_new_pdu (const struct coap_session_t *session)
 Creates a new CoAP PDU. More...
 
void coap_delete_pdu (coap_pdu_t *pdu)
 Dispose of an CoAP PDU and frees associated storage. More...
 
coap_pdu_tcoap_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. More...
 
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. More...
 
size_t coap_pdu_parse_size (coap_proto_t proto, const uint8_t *data, size_t length)
 Parses data to extract the message size. More...
 
int coap_pdu_parse_header (coap_pdu_t *pdu, coap_proto_t proto)
 Decode the protocol specific header for the specified PDU. More...
 
int coap_pdu_parse_opt (coap_pdu_t *pdu)
 Verify consistency in the given CoAP PDU structure and locate the data. More...
 
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. More...
 
int coap_add_token (coap_pdu_t *pdu, size_t len, const uint8_t *data)
 Adds token of length len to pdu. More...
 
size_t coap_insert_option (coap_pdu_t *pdu, uint16_t type, size_t len, const uint8_t *data)
 Inserts option of given type in the pdu with the appropriate data. More...
 
int coap_update_token (coap_pdu_t *pdu, size_t len, const uint8_t *data)
 Updates token in pdu with length len and data. More...
 
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. More...
 
int coap_remove_option (coap_pdu_t *pdu, uint16_t type)
 Removes option of given type from the pdu. More...
 
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. More...
 
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. More...
 
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. More...
 
int coap_get_data (const coap_pdu_t *pdu, size_t *len, uint8_t **data)
 Retrieves the length and data pointer of specified PDU. More...
 
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. More...
 
size_t coap_pdu_encode_header (coap_pdu_t *pdu, coap_proto_t proto)
 Compose the protocol specific header for the specified PDU. More...
 

Detailed Description

Pre-defined constants that reflect defaults for CoAP.

Definition in file pdu.h.

Macro Definition Documentation

◆ COAP_DEBUG_BUF_SIZE

#define COAP_DEBUG_BUF_SIZE   (8 + 1024 * 2)

Definition at line 63 of file pdu.h.

◆ COAP_DEFAULT_HOP_LIMIT

#define COAP_DEFAULT_HOP_LIMIT   16

Definition at line 35 of file pdu.h.

◆ COAP_DEFAULT_MAX_AGE

#define COAP_DEFAULT_MAX_AGE   60 /* default maximum object lifetime in seconds */

Definition at line 29 of file pdu.h.

◆ COAP_DEFAULT_MAX_PDU_RX_SIZE

#define COAP_DEFAULT_MAX_PDU_RX_SIZE   (8UL*1024*1024+256)

Definition at line 54 of file pdu.h.

◆ COAP_DEFAULT_MTU

#define COAP_DEFAULT_MTU   1152

Definition at line 31 of file pdu.h.

◆ COAP_DEFAULT_PORT

#define COAP_DEFAULT_PORT   5683 /* CoAP default UDP/TCP port */

Definition at line 27 of file pdu.h.

◆ COAP_DEFAULT_SCHEME

#define COAP_DEFAULT_SCHEME   "coap" /* the default scheme for CoAP URIs */

Definition at line 68 of file pdu.h.

◆ COAP_DEFAULT_URI_WELLKNOWN

#define COAP_DEFAULT_URI_WELLKNOWN   ".well-known/core"

well-known resources URI

Definition at line 71 of file pdu.h.

◆ COAP_DEFAULT_VERSION

#define COAP_DEFAULT_VERSION   1 /* version of CoAP supported */

Definition at line 67 of file pdu.h.

◆ COAP_DROPPED_RESPONSE

#define COAP_DROPPED_RESPONSE   -2

Indicates that a response is suppressed.

This will occur for error responses if the request was received via IP multicast.

Definition at line 253 of file pdu.h.

◆ COAP_ERROR_PHRASE_LENGTH

#define COAP_ERROR_PHRASE_LENGTH   32

maximum length of error phrase

Definition at line 174 of file pdu.h.

◆ COAP_INVALID_MID

#define COAP_INVALID_MID   -1

Indicates an invalid message id.

Definition at line 247 of file pdu.h.

◆ COAP_MAX_MESSAGE_SIZE_TCP0

#define COAP_MAX_MESSAGE_SIZE_TCP0   (COAP_MESSAGE_SIZE_OFFSET_TCP8-1) /* 12 */

Definition at line 44 of file pdu.h.

◆ COAP_MAX_MESSAGE_SIZE_TCP16

#define COAP_MAX_MESSAGE_SIZE_TCP16   (COAP_MESSAGE_SIZE_OFFSET_TCP32-1) /* 65804 */

Definition at line 46 of file pdu.h.

◆ COAP_MAX_MESSAGE_SIZE_TCP32

#define COAP_MAX_MESSAGE_SIZE_TCP32   (COAP_MESSAGE_SIZE_OFFSET_TCP32+0xFFFFFFFF)

Definition at line 47 of file pdu.h.

◆ COAP_MAX_MESSAGE_SIZE_TCP8

#define COAP_MAX_MESSAGE_SIZE_TCP8   (COAP_MESSAGE_SIZE_OFFSET_TCP16-1) /* 268 */

Definition at line 45 of file pdu.h.

◆ COAP_MAX_OPT

#define COAP_MAX_OPT   65535

the highest option number we know

Definition at line 148 of file pdu.h.

◆ COAP_MEDIATYPE_ANY

#define COAP_MEDIATYPE_ANY   0xff /* any media type */

Definition at line 238 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_CBOR

#define COAP_MEDIATYPE_APPLICATION_CBOR   60 /* application/cbor */

Definition at line 209 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT

#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT   96 /* application/cose; cose-type="cose-encrypt" */

Definition at line 215 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0

#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0   16 /* application/cose; cose-type="cose-encrypt0" */

Definition at line 216 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_COSE_KEY

#define COAP_MEDIATYPE_APPLICATION_COSE_KEY   101 /* application/cose-key */

Definition at line 220 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET

#define COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET   102 /* application/cose-key-set */

Definition at line 221 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_COSE_MAC

#define COAP_MEDIATYPE_APPLICATION_COSE_MAC   97 /* application/cose; cose-type="cose-mac" */

Definition at line 217 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_COSE_MAC0

#define COAP_MEDIATYPE_APPLICATION_COSE_MAC0   17 /* application/cose; cose-type="cose-mac0" */

Definition at line 218 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_COSE_SIGN

#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN   98 /* application/cose; cose-type="cose-sign" */

Definition at line 213 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_COSE_SIGN1

#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN1   18 /* application/cose; cose-type="cose-sign1" */

Definition at line 214 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_CWT

#define COAP_MEDIATYPE_APPLICATION_CWT   61 /* application/cwt, RFC 8392 */

Definition at line 210 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_DOTS_CBOR

#define COAP_MEDIATYPE_APPLICATION_DOTS_CBOR   271 /* application/dots+cbor */

Definition at line 234 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_EXI

#define COAP_MEDIATYPE_APPLICATION_EXI   47 /* application/exi */

Definition at line 207 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_JSON

#define COAP_MEDIATYPE_APPLICATION_JSON   50 /* application/json */

Definition at line 208 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_LINK_FORMAT

#define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT   40 /* application/link-format */

Definition at line 203 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_OCTET_STREAM

#define COAP_MEDIATYPE_APPLICATION_OCTET_STREAM   42 /* application/octet-stream */

Definition at line 205 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_RDF_XML

#define COAP_MEDIATYPE_APPLICATION_RDF_XML   43 /* application/rdf+xml */

Definition at line 206 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_SENML_CBOR

#define COAP_MEDIATYPE_APPLICATION_SENML_CBOR   112 /* application/senml+cbor */

Definition at line 226 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_SENML_EXI

#define COAP_MEDIATYPE_APPLICATION_SENML_EXI   114 /* application/senml-exi */

Definition at line 228 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_SENML_JSON

#define COAP_MEDIATYPE_APPLICATION_SENML_JSON   110 /* application/senml+json */

Definition at line 224 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_SENML_XML

#define COAP_MEDIATYPE_APPLICATION_SENML_XML   310 /* application/senml+xml */

Definition at line 230 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_SENSML_CBOR

#define COAP_MEDIATYPE_APPLICATION_SENSML_CBOR   113 /* application/sensml+cbor */

Definition at line 227 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_SENSML_EXI

#define COAP_MEDIATYPE_APPLICATION_SENSML_EXI   115 /* application/sensml-exi */

Definition at line 229 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_SENSML_JSON

#define COAP_MEDIATYPE_APPLICATION_SENSML_JSON   111 /* application/sensml+json */

Definition at line 225 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_SENSML_XML

#define COAP_MEDIATYPE_APPLICATION_SENSML_XML   311 /* application/sensml+xml */

Definition at line 231 of file pdu.h.

◆ COAP_MEDIATYPE_APPLICATION_XML

#define COAP_MEDIATYPE_APPLICATION_XML   41 /* application/xml */

Definition at line 204 of file pdu.h.

◆ COAP_MEDIATYPE_TEXT_PLAIN

#define COAP_MEDIATYPE_TEXT_PLAIN   0 /* text/plain (UTF-8) */

Definition at line 202 of file pdu.h.

◆ COAP_MESSAGE_ACK

#define COAP_MESSAGE_ACK   2 /* used to acknowledge confirmable messages */

Definition at line 77 of file pdu.h.

◆ COAP_MESSAGE_CON

#define COAP_MESSAGE_CON   0 /* confirmable message (requires ACK/RST) */

Definition at line 75 of file pdu.h.

◆ COAP_MESSAGE_NON

#define COAP_MESSAGE_NON   1 /* non-confirmable message (one-shot message) */

Definition at line 76 of file pdu.h.

◆ COAP_MESSAGE_RST

#define COAP_MESSAGE_RST   3 /* indicates error in received messages */

Definition at line 78 of file pdu.h.

◆ COAP_MESSAGE_SIZE_OFFSET_TCP16

#define COAP_MESSAGE_SIZE_OFFSET_TCP16   269 /* 13 + 256 */

Definition at line 40 of file pdu.h.

◆ COAP_MESSAGE_SIZE_OFFSET_TCP32

#define COAP_MESSAGE_SIZE_OFFSET_TCP32   65805 /* 269 + 65536 */

Definition at line 41 of file pdu.h.

◆ COAP_MESSAGE_SIZE_OFFSET_TCP8

#define COAP_MESSAGE_SIZE_OFFSET_TCP8   13

Definition at line 39 of file pdu.h.

◆ COAP_OPTION_ACCEPT

#define COAP_OPTION_ACCEPT   17 /* C___E__, uint, 0-2 B, RFC7252 */

Definition at line 138 of file pdu.h.

◆ COAP_OPTION_BLOCK1

#define COAP_OPTION_BLOCK1   27 /* CU-_E_U, uint, 0-3 B, RFC7959 */

Definition at line 141 of file pdu.h.

◆ COAP_OPTION_BLOCK2

#define COAP_OPTION_BLOCK2   23 /* CU-_E_U, uint, 0-3 B, RFC7959 */

Definition at line 140 of file pdu.h.

◆ COAP_OPTION_CONTENT_FORMAT

#define COAP_OPTION_CONTENT_FORMAT   12 /* ____E__, uint, 0-2 B, RFC7252 */

Definition at line 132 of file pdu.h.

◆ COAP_OPTION_CONTENT_TYPE

#define COAP_OPTION_CONTENT_TYPE   COAP_OPTION_CONTENT_FORMAT

Definition at line 133 of file pdu.h.

◆ COAP_OPTION_DATA

#define COAP_OPTION_DATA (   option)    ((unsigned char *)&(option) + sizeof(coap_option))

Definition at line 273 of file pdu.h.

◆ COAP_OPTION_ETAG

#define COAP_OPTION_ETAG   4 /* ___RE__, opaque, 1-8 B, RFC7252 */

Definition at line 125 of file pdu.h.

◆ COAP_OPTION_HOP_LIMIT

#define COAP_OPTION_HOP_LIMIT   16 /* ______U, uint, 1 B, RFC8768 */

Definition at line 137 of file pdu.h.

◆ COAP_OPTION_IF_MATCH

#define COAP_OPTION_IF_MATCH   1 /* C__RE__, opaque, 0-8 B, RFC7252 */

Definition at line 123 of file pdu.h.

◆ COAP_OPTION_IF_NONE_MATCH

#define COAP_OPTION_IF_NONE_MATCH   5 /* C___E__, empty, 0 B, RFC7252 */

Definition at line 126 of file pdu.h.

◆ COAP_OPTION_KEY

#define COAP_OPTION_KEY (   option)    (option).key

Definition at line 271 of file pdu.h.

◆ COAP_OPTION_LENGTH

#define COAP_OPTION_LENGTH (   option)    (option).length

Definition at line 272 of file pdu.h.

◆ COAP_OPTION_LOCATION_PATH

#define COAP_OPTION_LOCATION_PATH   8 /* ___RE__, String, 0-255 B, RFC7252 */

Definition at line 129 of file pdu.h.

◆ COAP_OPTION_LOCATION_QUERY

#define COAP_OPTION_LOCATION_QUERY   20 /* ___RE__, String, 0-255 B, RFC7252 */

Definition at line 139 of file pdu.h.

◆ COAP_OPTION_MAXAGE

#define COAP_OPTION_MAXAGE   14 /* _U-_E_U, uint, 0-4 B, RFC7252 */

Definition at line 135 of file pdu.h.

◆ COAP_OPTION_NORESPONSE

#define COAP_OPTION_NORESPONSE   258 /* _U-_E_U, uint, 0-1 B, RFC7967 */

Definition at line 146 of file pdu.h.

◆ COAP_OPTION_OBSERVE

#define COAP_OPTION_OBSERVE   6 /* _U-_E_U, empty/uint,0/0-3 B, RFC7641 */

Definition at line 127 of file pdu.h.

◆ COAP_OPTION_OSCORE

#define COAP_OPTION_OSCORE   9 /* C_____U, *, 0-255 B, RFC8613 */

Definition at line 130 of file pdu.h.

◆ COAP_OPTION_PROXY_SCHEME

#define COAP_OPTION_PROXY_SCHEME   39 /* CU-___U, String, 1-255 B, RFC7252 */

Definition at line 144 of file pdu.h.

◆ COAP_OPTION_PROXY_URI

#define COAP_OPTION_PROXY_URI   35 /* CU-___U, String, 1-1034 B, RFC7252 */

Definition at line 143 of file pdu.h.

◆ COAP_OPTION_SIZE1

#define COAP_OPTION_SIZE1   60 /* __N_E_U, uint, 0-4 B, RFC7252 */

Definition at line 145 of file pdu.h.

◆ COAP_OPTION_SIZE2

#define COAP_OPTION_SIZE2   28 /* __N_E_U, uint, 0-4 B, RFC7959 */

Definition at line 142 of file pdu.h.

◆ COAP_OPTION_URI_HOST

#define COAP_OPTION_URI_HOST   3 /* CU-___U, String, 1-255 B, RFC7252 */

Definition at line 124 of file pdu.h.

◆ COAP_OPTION_URI_PATH

#define COAP_OPTION_URI_PATH   11 /* CU-RE__, String, 0-255 B, RFC7252 */

Definition at line 131 of file pdu.h.

◆ COAP_OPTION_URI_PORT

#define COAP_OPTION_URI_PORT   7 /* CU-___U, uint, 0-2 B, RFC7252 */

Definition at line 128 of file pdu.h.

◆ COAP_OPTION_URI_QUERY

#define COAP_OPTION_URI_QUERY   15 /* CU-RE__, String, 1-255 B, RFC7252 */

Definition at line 136 of file pdu.h.

◆ COAP_PAYLOAD_START

#define COAP_PAYLOAD_START   0xFF /* payload marker */

Definition at line 257 of file pdu.h.

◆ COAP_PDU_DELAYED

#define COAP_PDU_DELAYED   -3

Definition at line 255 of file pdu.h.

◆ COAP_PDU_IS_EMPTY

#define COAP_PDU_IS_EMPTY (   pdu)    ((pdu)->code == 0)

Definition at line 318 of file pdu.h.

◆ COAP_PDU_IS_REQUEST

#define COAP_PDU_IS_REQUEST (   pdu)    (!COAP_PDU_IS_EMPTY(pdu) && (pdu)->code < 32)

Definition at line 319 of file pdu.h.

◆ COAP_PDU_IS_RESPONSE

#define COAP_PDU_IS_RESPONSE (   pdu)    ((pdu)->code >= 64 && (pdu)->code < 224)

Definition at line 320 of file pdu.h.

◆ COAP_PDU_IS_SIGNALING

#define COAP_PDU_IS_SIGNALING (   pdu)    ((pdu)->code >= 224)

Definition at line 321 of file pdu.h.

◆ COAP_PDU_MAX_TCP_HEADER_SIZE

#define COAP_PDU_MAX_TCP_HEADER_SIZE   6

Definition at line 324 of file pdu.h.

◆ COAP_PDU_MAX_UDP_HEADER_SIZE

#define COAP_PDU_MAX_UDP_HEADER_SIZE   4

Definition at line 323 of file pdu.h.

◆ COAP_PROTO_DTLS

#define COAP_PROTO_DTLS   2

Definition at line 351 of file pdu.h.

◆ COAP_PROTO_NONE

#define COAP_PROTO_NONE   0

coap_proto_t values

Definition at line 349 of file pdu.h.

◆ COAP_PROTO_TCP

#define COAP_PROTO_TCP   3

Definition at line 352 of file pdu.h.

◆ COAP_PROTO_TLS

#define COAP_PROTO_TLS   4

Definition at line 353 of file pdu.h.

◆ COAP_PROTO_UDP

#define COAP_PROTO_UDP   1

Definition at line 350 of file pdu.h.

◆ COAP_RESPONSE_CLASS

#define COAP_RESPONSE_CLASS (   C)    (((C) >> 5) & 0xFF)

Definition at line 159 of file pdu.h.

◆ COAP_RESPONSE_CODE

#define COAP_RESPONSE_CODE (   N)    (((N)/100 << 5) | (N)%100)

Definition at line 156 of file pdu.h.

◆ COAP_SIGNALING_ABORT

#define COAP_SIGNALING_ABORT   COAP_SIGNALING_CODE(705)

Definition at line 187 of file pdu.h.

◆ COAP_SIGNALING_CODE

#define COAP_SIGNALING_CODE (   N)    (((N)/100 << 5) | (N)%100)

Definition at line 182 of file pdu.h.

◆ COAP_SIGNALING_CSM

#define COAP_SIGNALING_CSM   COAP_SIGNALING_CODE(701)

Definition at line 183 of file pdu.h.

◆ COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS

#define COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS   2

Definition at line 195 of file pdu.h.

◆ COAP_SIGNALING_OPTION_BAD_CSM_OPTION

#define COAP_SIGNALING_OPTION_BAD_CSM_OPTION   2

Definition at line 198 of file pdu.h.

◆ COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER

#define COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER   4

Definition at line 191 of file pdu.h.

◆ COAP_SIGNALING_OPTION_CUSTODY

#define COAP_SIGNALING_OPTION_CUSTODY   2

Definition at line 193 of file pdu.h.

◆ COAP_SIGNALING_OPTION_HOLD_OFF

#define COAP_SIGNALING_OPTION_HOLD_OFF   4

Definition at line 196 of file pdu.h.

◆ COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE

#define COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE   2

Definition at line 190 of file pdu.h.

◆ COAP_SIGNALING_PING

#define COAP_SIGNALING_PING   COAP_SIGNALING_CODE(702)

Definition at line 184 of file pdu.h.

◆ COAP_SIGNALING_PONG

#define COAP_SIGNALING_PONG   COAP_SIGNALING_CODE(703)

Definition at line 185 of file pdu.h.

◆ COAP_SIGNALING_RELEASE

#define COAP_SIGNALING_RELEASE   COAP_SIGNALING_CODE(704)

Definition at line 186 of file pdu.h.

◆ COAPS_DEFAULT_PORT

#define COAPS_DEFAULT_PORT   5684 /* CoAP default UDP/TCP port for secure transmission */

Definition at line 28 of file pdu.h.

Typedef Documentation

◆ coap_mid_t

typedef int coap_mid_t

coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.

Valid message ids are 0 to 2^16. Negative values are error codes.

Definition at line 244 of file pdu.h.

◆ coap_proto_t

typedef uint8_t coap_proto_t

Definition at line 345 of file pdu.h.

◆ coap_request_t

Enumeration Type Documentation

◆ coap_request_t

Enumerator
COAP_REQUEST_GET 
COAP_REQUEST_POST 
COAP_REQUEST_PUT 
COAP_REQUEST_DELETE 
COAP_REQUEST_FETCH 
COAP_REQUEST_PATCH 
COAP_REQUEST_IPATCH 

Definition at line 82 of file pdu.h.

◆ coap_response_code

Set of response codes available for a response packet.

To be used when creating a response.

Enumerator
COAP_RESPONSE_CODE_OK 
COAP_RESPONSE_CODE_CREATED 
COAP_RESPONSE_CODE_DELETED 
COAP_RESPONSE_CODE_VALID 
COAP_RESPONSE_CODE_CHANGED 
COAP_RESPONSE_CODE_CONTENT 
COAP_RESPONSE_CODE_CONTINUE 
COAP_RESPONSE_CODE_BAD_REQUEST 
COAP_RESPONSE_CODE_UNAUTHORIZED 
COAP_RESPONSE_CODE_BAD_OPTION 
COAP_RESPONSE_CODE_FORBIDDEN 
COAP_RESPONSE_CODE_NOT_FOUND 
COAP_RESPONSE_CODE_NOT_ALLOWED 
COAP_RESPONSE_CODE_NOT_ACCEPTABLE 
COAP_RESPONSE_CODE_INCOMPLETE 
COAP_RESPONSE_CODE_CONFLICT 
COAP_RESPONSE_CODE_PRECONDITION_FAILED 
COAP_RESPONSE_CODE_REQUEST_TOO_LARGE 
COAP_RESPONSE_CODE_UNSUPPORTED_CONTENT_FORMAT 
COAP_RESPONSE_CODE_UNPROCESSABLE 
COAP_RESPONSE_CODE_TOO_MANY_REQUESTS 
COAP_RESPONSE_CODE_INTERNAL_ERROR 
COAP_RESPONSE_CODE_NOT_IMPLEMENTED 
COAP_RESPONSE_CODE_BAD_GATEWAY 
COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE 
COAP_RESPONSE_CODE_GATEWAY_TIMEOUT 
COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED 
COAP_RESPONSE_CODE_HOP_LIMIT_REACHED 

Definition at line 360 of file pdu.h.

Function Documentation

◆ 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.

Note that the PDU's data is destroyed by coap_add_option(). coap_add_data() must be called only once per PDU, otherwise the result is undefined.

Definition at line 614 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 copy it.

Note that the PDU's data is destroyed by coap_add_option(). coap_add_data() must be have been called once for this PDU, otherwise the result is undefined. The actual data must be copied at the returned location.

Definition at line 626 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_add_option()

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.

coap_add_option() destroys the PDU's data, so coap_add_data() must be called after all options have been added. As coap_add_token() destroys the options following the token, the token must be added before coap_add_option() is called. This function returns the number of bytes written or 0 on error.

Definition at line 535 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

Adding the token destroys any following contents of the pdu. Hence options and data must be added after coap_add_token() has been called. In pdu, length is set to len + 4, and max_delta is set to 0. This function returns 0 on error or a value greater than zero on success.

Parameters
pduThe PDU where the token is to be added.
lenThe length of the new token.
dataThe token to add.
Returns
A value greater than zero on success, or 0 on error.

Definition at line 249 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_delete_pdu()

void coap_delete_pdu ( coap_pdu_t pdu)

Dispose of an CoAP PDU and frees associated storage.

Not that in general you should not call this function directly. When a PDU is sent with coap_send() or coap_send_large(), coap_delete_pdu() will be called automatically for you.

Parameters
pduThe PDU for free off.

Definition at line 133 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_get_data()

int coap_get_data ( const coap_pdu_t pdu,
size_t *  len,
uint8_t **  data 
)

Retrieves the length and data pointer of specified PDU.

Returns 0 on error or 1 if *len and *data have correct values. Note that these values are destroyed with the pdu.

Definition at line 644 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

Note: The data pointed to on return is destroyed when the PDU is destroyed.

Parameters
pduThe specified PDU.
lenReturns the length of the current data
dataReturns the ptr to the current data
offsetReturns the offset of the current data from the start of the body comprising of many blocks (RFC7959)
totalReturns the total size of the body. If offset + length < total, then there is more data to follow.
Returns
1 if len, data, offset and total are correctly filled in, else 0 if there is no data.

Definition at line 658 of file pdu.c.

+ Here is the caller graph for this function:

◆ coap_insert_option()

size_t coap_insert_option ( coap_pdu_t pdu,
uint16_t  type,
size_t  len,
const uint8_t *  data 
)

Inserts option of given type in the pdu with the appropriate data.

The option will be inserted in the appropriate place in the options in the pdu.

Internal use only.

Definition at line 405 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_new_pdu()

coap_pdu_t* coap_new_pdu ( const struct coap_session_t session)

Creates a new CoAP PDU.

Parameters
sessionThe session that will be using this PDU
Returns
The skeletal PDU or NULL if failure.

Definition at line 125 of file pdu.c.

+ Here is the call graph for this function:

◆ coap_pdu_check_resize()

int coap_pdu_check_resize ( coap_pdu_t pdu,
size_t  new_size 
)

Dynamically grows the size of pdu to new_size if needed.

The new size must not exceed the PDU's configured maximum size. On success, this function returns 1, otherwise 0.

Internal use only.

Parameters
pduThe PDU to resize.
new_sizeThe new size in bytes.
Returns
1 if the operation succeeded, 0 otherwise.

Definition at line 232 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_pdu_clear()

void coap_pdu_clear ( coap_pdu_t pdu,
size_t  size 
)

Clears any contents from pdu and resets used_size, and data pointers.

max_size is set to size, any other field is set to 0. Note that pdu must be a valid pointer to a coap_pdu_t object created e.g. by coap_pdu_init().

Definition at line 35 of file pdu.c.

+ Here is the caller graph for this function:

◆ coap_pdu_duplicate()

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.

Specific options can be ignored and not copied across. The PDU data payload is not copied across.

Parameters
old_pduThe PDU to duplicate
sessionThe session that will be using this PDU.
token_lengthThe length of the token to use in this duplicated PDU.
tokenThe token to use in this duplicated PDU.
drop_optionsA list of options not to copy into the duplicated PDU. If NULL, then all options are copied across.
Returns
The duplicated PDU or NULL if failure.

Definition at line 146 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_pdu_encode_header()

size_t coap_pdu_encode_header ( coap_pdu_t pdu,
coap_proto_t  proto 
)

Compose the protocol specific header for the specified PDU.

Parameters
pduA newly composed PDU.
protoThe target wire protocol.
Returns
Number of header bytes prepended before pdu->token or 0 on error.

Definition at line 1120 of file pdu.c.

+ Here is the caller graph for this function:

◆ coap_pdu_init()

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.

The function returns a pointer to the node coap_pdu_t object on success, or NULL on error. The storage allocated for the result must be released with coap_delete_pdu() if coap_send() or coap_send_large() is not called.

Parameters
typeThe type of the PDU (one of COAP_MESSAGE_CON, COAP_MESSAGE_NON, COAP_MESSAGE_ACK, COAP_MESSAGE_RST).
codeThe message code.
midThe transcation id to set or 0 if unknown / not applicable.
sizeThe maximum allowed number of byte for the message.
Returns
A pointer to the new PDU object or NULL on error.

Definition at line 85 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

The target pdu must be large enough to This function returns 0 on error or a number greater than zero on success.

Parameters
protoSession's protocol
dataThe raw data to parse as CoAP PDU.
lengthThe actual size of data.
pduThe PDU structure to fill. Note that the structure must provide space to hold at least the token and options part of the message.
Returns
1 on success or 0 on error.

Definition at line 1095 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_pdu_parse_header()

int coap_pdu_parse_header ( coap_pdu_t pdu,
coap_proto_t  proto 
)

Decode the protocol specific header for the specified PDU.

Parameters
pduA newly received PDU.
protoThe target wire protocol.
Returns
1 for success or 0 on error.

Definition at line 818 of file pdu.c.

+ Here is the caller graph for this function:

◆ coap_pdu_parse_header_size()

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.

This function returns 0 on error or a number greater than zero on success.

Parameters
protoSession's protocol
dataThe first byte of raw data to parse as CoAP PDU.
Returns
A value greater than zero on success or 0 on error.

Definition at line 763 of file pdu.c.

+ Here is the caller graph for this function:

◆ coap_pdu_parse_opt()

int coap_pdu_parse_opt ( coap_pdu_t pdu)

Verify consistency in the given CoAP PDU structure and locate the data.

This function returns 0 on error or a number greater than zero on success. This function only parses the token and options, up to the payload start marker.

Parameters
pduThe PDU structure to.
Returns
1 on success or 0 on error.

Definition at line 970 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_pdu_parse_size()

size_t coap_pdu_parse_size ( coap_proto_t  proto,
const uint8_t *  data,
size_t  length 
)

Parses data to extract the message size.

length must be at least coap_pdu_parse_header_size(proto, data). This function returns 0 on error or a number greater than zero on success.

Parameters
protoSession's protocol
dataThe raw data to parse as CoAP PDU.
lengthThe actual size of data.
Returns
A value greater than zero on success or 0 on error.

Definition at line 786 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_pdu_resize()

int coap_pdu_resize ( coap_pdu_t pdu,
size_t  new_size 
)

Dynamically grows the size of pdu to new_size.

The new size must not exceed the PDU's configure maximum size. On success, this function returns 1, otherwise 0.

Parameters
pduThe PDU to resize.
new_sizeThe new size in bytes.
Returns
1 if the operation succeeded, 0 otherwise.

Definition at line 198 of file pdu.c.

+ Here is the caller graph for this function:

◆ coap_remove_option()

int coap_remove_option ( coap_pdu_t pdu,
uint16_t  type 
)

Removes option of given type from the pdu.

Internal use only.

Definition at line 305 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_response_phrase()

const char* coap_response_phrase ( unsigned char  code)

Returns a human-readable response phrase for the specified CoAP response code.

This function returns NULL if not found.

Parameters
codeThe response code for which the literal phrase should be retrieved.
Returns
A zero-terminated string describing the error, or NULL if not found.

Definition at line 722 of file pdu.c.

+ Here is the caller graph for this function:

◆ coap_update_option()

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.

Internal use only.

Definition at line 494 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_update_token()

int coap_update_token ( coap_pdu_t pdu,
size_t  len,
const uint8_t *  data 
)

Updates token in pdu with length len and data.

This function returns 0 on error or a value greater than zero on success.

Internal use only

Parameters
pduThe PDU where the token is to be updated.
lenThe length of the new token.
dataThe token to add.
Returns
A value greater than zero on success, or 0 on error.

Definition at line 273 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: