Documentation
Includes
uri.h
#include "uri.h"
lwip/pbuf.h
#include <lwip/pbuf.h>
stdint.h
#include <stdint.h>
Macros
Marco COAP_PDU_H_
#define COAP_PDU_H_
Marco COAP_DEFAULT_PORT
#define COAP_DEFAULT_PORT 5683 /* CoAP default UDP/TCP port */
Marco COAPS_DEFAULT_PORT
#define COAPS_DEFAULT_PORT 5684 /* CoAP default UDP/TCP port for secure transmission */
Marco COAP_DEFAULT_MAX_AGE
#define COAP_DEFAULT_MAX_AGE 60 /* default maximum object lifetime in seconds */
Marco COAP_DEFAULT_MTU
#define COAP_DEFAULT_MTU 1152
Marco COAP_MESSAGE_SIZE_OFFSET_TCP8
#define COAP_MESSAGE_SIZE_OFFSET_TCP8 13
Marco COAP_MESSAGE_SIZE_OFFSET_TCP16
#define COAP_MESSAGE_SIZE_OFFSET_TCP16 269 /* 13 + 256 */
Marco COAP_MESSAGE_SIZE_OFFSET_TCP32
#define COAP_MESSAGE_SIZE_OFFSET_TCP32 65805 /* 269 + 65536 */
Marco COAP_MAX_MESSAGE_SIZE_TCP0
#define COAP_MAX_MESSAGE_SIZE_TCP0 (COAP_MESSAGE_SIZE_OFFSET_TCP8-1) /* 12 */
Marco COAP_MAX_MESSAGE_SIZE_TCP8
#define COAP_MAX_MESSAGE_SIZE_TCP8 (COAP_MESSAGE_SIZE_OFFSET_TCP16-1) /* 268 */
Marco COAP_MAX_MESSAGE_SIZE_TCP16
#define COAP_MAX_MESSAGE_SIZE_TCP16 (COAP_MESSAGE_SIZE_OFFSET_TCP32-1) /* 65804 */
Marco COAP_MAX_MESSAGE_SIZE_TCP32
#define COAP_MAX_MESSAGE_SIZE_TCP32 (COAP_MESSAGE_SIZE_OFFSET_TCP32+4294967295)
Marco COAP_DEFAULT_MAX_PDU_RX_SIZE
#define COAP_DEFAULT_MAX_PDU_RX_SIZE (COAP_MAX_MESSAGE_SIZE_TCP16+4)
Marco COAP_DEFAULT_MAX_PDU_RX_SIZE
#define COAP_DEFAULT_MAX_PDU_RX_SIZE (8*1024*1024+256)
Marco COAP_DEBUG_BUF_SIZE
#define COAP_DEBUG_BUF_SIZE 128
Marco COAP_DEBUG_BUF_SIZE
#define COAP_DEBUG_BUF_SIZE (8 + 1024 * 2)
Marco COAP_DEFAULT_VERSION
#define COAP_DEFAULT_VERSION 1 /* version of CoAP supported */
Marco COAP_DEFAULT_SCHEME
#define COAP_DEFAULT_SCHEME "coap" /* the default scheme for CoAP URIs */
Marco COAP_DEFAULT_URI_WELLKNOWN
#define COAP_DEFAULT_URI_WELLKNOWN ".well-known/core"
Marco COAP_MESSAGE_CON
#define COAP_MESSAGE_CON 0 /* confirmable message (requires ACK/RST) */
Marco COAP_MESSAGE_NON
#define COAP_MESSAGE_NON 1 /* non-confirmable message (one-shot message) */
Marco COAP_MESSAGE_ACK
#define COAP_MESSAGE_ACK 2 /* used to acknowledge confirmable messages */
Marco COAP_MESSAGE_RST
#define COAP_MESSAGE_RST 3 /* indicates error in received messages */
Marco COAP_REQUEST_GET
#define COAP_REQUEST_GET 1
Marco COAP_REQUEST_POST
#define COAP_REQUEST_POST 2
Marco COAP_REQUEST_PUT
#define COAP_REQUEST_PUT 3
Marco COAP_REQUEST_DELETE
#define COAP_REQUEST_DELETE 4
Marco COAP_REQUEST_FETCH
#define COAP_REQUEST_FETCH 5 /* RFC 8132 */
Marco COAP_REQUEST_PATCH
#define COAP_REQUEST_PATCH 6 /* RFC 8132 */
Marco COAP_REQUEST_IPATCH
#define COAP_REQUEST_IPATCH 7 /* RFC 8132 */
Marco COAP_OPTION_IF_MATCH
#define COAP_OPTION_IF_MATCH 1 /* C, opaque, 0-8 B, (none) */
Marco COAP_OPTION_URI_HOST
#define COAP_OPTION_URI_HOST 3 /* C, String, 1-255 B, destination address */
Marco COAP_OPTION_ETAG
#define COAP_OPTION_ETAG 4 /* E, opaque, 1-8 B, (none) */
Marco COAP_OPTION_IF_NONE_MATCH
#define COAP_OPTION_IF_NONE_MATCH 5 /* empty, 0 B, (none) */
Marco COAP_OPTION_URI_PORT
#define COAP_OPTION_URI_PORT 7 /* C, uint, 0-2 B, destination port */
Marco COAP_OPTION_LOCATION_PATH
#define COAP_OPTION_LOCATION_PATH 8 /* E, String, 0-255 B, - */
Marco COAP_OPTION_URI_PATH
#define COAP_OPTION_URI_PATH 11 /* C, String, 0-255 B, (none) */
Marco COAP_OPTION_CONTENT_FORMAT
#define COAP_OPTION_CONTENT_FORMAT 12 /* E, uint, 0-2 B, (none) */
Marco COAP_OPTION_CONTENT_TYPE
#define COAP_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
Marco COAP_OPTION_MAXAGE
#define COAP_OPTION_MAXAGE 14 /* E, uint, 0--4 B, 60 Seconds */
Marco COAP_OPTION_URI_QUERY
#define COAP_OPTION_URI_QUERY 15 /* C, String, 1-255 B, (none) */
Marco COAP_OPTION_ACCEPT
#define COAP_OPTION_ACCEPT 17 /* C, uint, 0-2 B, (none) */
Marco COAP_OPTION_LOCATION_QUERY
#define COAP_OPTION_LOCATION_QUERY 20 /* E, String, 0-255 B, (none) */
Marco COAP_OPTION_SIZE2
#define COAP_OPTION_SIZE2 28 /* E, uint, 0-4 B, (none) */
Marco COAP_OPTION_PROXY_URI
#define COAP_OPTION_PROXY_URI 35 /* C, String, 1-1034 B, (none) */
Marco COAP_OPTION_PROXY_SCHEME
#define COAP_OPTION_PROXY_SCHEME 39 /* C, String, 1-255 B, (none) */
Marco COAP_OPTION_SIZE1
#define COAP_OPTION_SIZE1 60 /* E, uint, 0-4 B, (none) */
Marco COAP_OPTION_OBSERVE
#define COAP_OPTION_OBSERVE 6 /* E, empty/uint, 0 B/0-3 B, (none) */
Marco COAP_OPTION_SUBSCRIPTION
#define COAP_OPTION_SUBSCRIPTION COAP_OPTION_OBSERVE
Marco COAP_OPTION_BLOCK2
#define COAP_OPTION_BLOCK2 23 /* C, uint, 0--3 B, (none) */
Marco COAP_OPTION_BLOCK1
#define COAP_OPTION_BLOCK1 27 /* C, uint, 0--3 B, (none) */
Marco COAP_OPTION_NORESPONSE
#define COAP_OPTION_NORESPONSE 258 /* N, uint, 0--1 B, 0 */
Marco COAP_MAX_OPT
#define COAP_MAX_OPT 65535 /**< the highest option number we know */
Marco COAP_RESPONSE_CODE(N)
#define COAP_RESPONSE_CODE(N) (((N)/100 << 5) | (N)%100)
Marco COAP_RESPONSE_CLASS(C)
#define COAP_RESPONSE_CLASS(C) (((C) >> 5) & 255)
Marco COAP_ERROR_PHRASE_LENGTH
#define COAP_ERROR_PHRASE_LENGTH 32 /**< maximum length of error phrase */
Marco coap_response_phrase(x)
#define coap_response_phrase(x) ((char *)NULL)
Marco COAP_ERROR_PHRASE_LENGTH
#define COAP_ERROR_PHRASE_LENGTH 0 /**< maximum length of error phrase */
Marco COAP_RESPONSE_100
#define COAP_RESPONSE_100 40 /* 100 Continue */
Marco COAP_RESPONSE_200
#define COAP_RESPONSE_200 COAP_RESPONSE_CODE(200) /* 2.00 OK */
Marco COAP_RESPONSE_201
#define COAP_RESPONSE_201 COAP_RESPONSE_CODE(201) /* 2.01 Created */
Marco COAP_RESPONSE_304
#define COAP_RESPONSE_304 COAP_RESPONSE_CODE(203) /* 2.03 Valid */
Marco COAP_RESPONSE_400
#define COAP_RESPONSE_400 COAP_RESPONSE_CODE(400) /* 4.00 Bad Request */
Marco COAP_RESPONSE_404
#define COAP_RESPONSE_404 COAP_RESPONSE_CODE(404) /* 4.04 Not Found */
Marco COAP_RESPONSE_405
#define COAP_RESPONSE_405 COAP_RESPONSE_CODE(405) /* 4.05 Method Not Allowed */
Marco COAP_RESPONSE_415
#define COAP_RESPONSE_415 COAP_RESPONSE_CODE(415) /* 4.15 Unsupported Media Type */
Marco COAP_RESPONSE_500
#define COAP_RESPONSE_500 COAP_RESPONSE_CODE(500) /* 5.00 Internal Server Error */
Marco COAP_RESPONSE_501
#define COAP_RESPONSE_501 COAP_RESPONSE_CODE(501) /* 5.01 Not Implemented */
Marco COAP_RESPONSE_503
#define COAP_RESPONSE_503 COAP_RESPONSE_CODE(503) /* 5.03 Service Unavailable */
Marco COAP_RESPONSE_504
#define COAP_RESPONSE_504 COAP_RESPONSE_CODE(504) /* 5.04 Gateway Timeout */
Marco COAP_RESPONSE_X_242
#define COAP_RESPONSE_X_242 COAP_RESPONSE_CODE(402) /* Critical Option not supported */
Marco COAP_SIGNALING_CODE(N)
#define COAP_SIGNALING_CODE(N) (((N)/100 << 5) | (N)%100)
Marco COAP_SIGNALING_CSM
#define COAP_SIGNALING_CSM COAP_SIGNALING_CODE(701)
Marco COAP_SIGNALING_PING
#define COAP_SIGNALING_PING COAP_SIGNALING_CODE(702)
Marco COAP_SIGNALING_PONG
#define COAP_SIGNALING_PONG COAP_SIGNALING_CODE(703)
Marco COAP_SIGNALING_RELEASE
#define COAP_SIGNALING_RELEASE COAP_SIGNALING_CODE(704)
Marco COAP_SIGNALING_ABORT
#define COAP_SIGNALING_ABORT COAP_SIGNALING_CODE(705)
Marco COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE
#define COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE 2
Marco COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER
#define COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER 4
Marco COAP_SIGNALING_OPTION_CUSTODY
#define COAP_SIGNALING_OPTION_CUSTODY 2
Marco COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS
#define COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS 2
Marco COAP_SIGNALING_OPTION_HOLD_OFF
#define COAP_SIGNALING_OPTION_HOLD_OFF 4
Marco COAP_SIGNALING_OPTION_BAD_CSM_OPTION
#define COAP_SIGNALING_OPTION_BAD_CSM_OPTION 2
Marco COAP_MEDIATYPE_TEXT_PLAIN
#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_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_ANY 255 /* any media type */
Marco COAP_INVALID_TID
#define COAP_INVALID_TID -1
Marco COAP_DROPPED_RESPONSE
#define COAP_DROPPED_RESPONSE -2
Marco COAP_PDU_DELAYED
#define COAP_PDU_DELAYED -3
Marco COAP_OPT_LONG
#define COAP_OPT_LONG 15 /* OC == 0b1111 indicates that the option list
* in a CoAP message is limited by 0b11110000
* marker */
Marco COAP_OPT_END
#define COAP_OPT_END 240 /* end marker */
Marco COAP_PAYLOAD_START
#define COAP_PAYLOAD_START 255 /* payload marker */
Marco COAP_OPTION_KEY(option)
#define COAP_OPTION_KEY(option) (option).key
Marco COAP_OPTION_LENGTH(option)
#define COAP_OPTION_LENGTH(option) (option).length
Marco COAP_OPTION_DATA(option)
#define COAP_OPTION_DATA(option) ((unsigned char *)&(option) + sizeof(coap_option))
Marco COAP_PDU_IS_EMPTY(pdu)
#define COAP_PDU_IS_EMPTY(pdu) ((pdu)->code == 0)
Marco COAP_PDU_IS_REQUEST(pdu)
#define COAP_PDU_IS_REQUEST(pdu) (!COAP_PDU_IS_EMPTY(pdu) && (pdu)->code < 32)
Marco COAP_PDU_IS_RESPONSE(pdu)
#define COAP_PDU_IS_RESPONSE(pdu) ((pdu)->code >= 64 && (pdu)->code < 224)
Marco COAP_PDU_IS_SIGNALING(pdu)
#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
Marco COAP_PROTO_NONE
#define COAP_PROTO_NONE 0
Marco COAP_PROTO_UDP
#define COAP_PROTO_UDP 1
Marco COAP_PROTO_DTLS
#define COAP_PROTO_DTLS 2
Marco COAP_PROTO_TCP
#define COAP_PROTO_TCP 3
Marco COAP_PROTO_TLS
#define COAP_PROTO_TLS 4
Functions
Func coap_pdu_resize
int coap_pdu_resize(coap_pdu_t *pdu, size_t new_size);
Func coap_pdu_clear
void coap_pdu_clear(coap_pdu_t *pdu, size_t size);
Func coap_delete_pdu
void coap_delete_pdu(coap_pdu_t *);
size_t coap_pdu_parse_header_size(coap_proto_t proto,
const uint8_t *data);
Func coap_pdu_parse_size
size_t coap_pdu_parse_size(coap_proto_t proto,
const uint8_t *data,
size_t length);
int coap_pdu_parse_header(coap_pdu_t *pdu, coap_proto_t proto);
Func coap_pdu_parse_opt
int coap_pdu_parse_opt(coap_pdu_t *pdu);
Func coap_pdu_parse
int coap_pdu_parse(coap_proto_t proto,
const uint8_t *data,
size_t length,
coap_pdu_t *pdu);
Func coap_add_token
int coap_add_token(coap_pdu_t *pdu,
size_t len,
const uint8_t *data);
Func coap_add_option
size_t coap_add_option(coap_pdu_t *pdu,
uint16_t type,
size_t len,
const uint8_t *data);
Func coap_add_option_later
uint8_t *coap_add_option_later(coap_pdu_t *pdu,
uint16_t type,
size_t len);
Func coap_add_data
int coap_add_data(coap_pdu_t *pdu,
size_t len,
const uint8_t *data);
Func coap_add_data_after
uint8_t *coap_add_data_after(coap_pdu_t *pdu, size_t len);
Func coap_get_data
int coap_get_data(const coap_pdu_t *pdu,
size_t *len,
uint8_t **data);
size_t coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto);
Vars
Variable coap_session_t
struct coap_session_t;
Variable COAP_DEPRECATED
COAP_DEPRECATED typedef struct {
uint16_t key; /* the option key (no delta coding) */
unsigned int length;
} coap_option;
Variable coap_pdu_t
coap_pdu_t * coap_pdu_from_pbuf(struct pbuf *pbuf);
Variable coap_pdu_t
coap_pdu_t *
coap_pdu_init(uint8_t type, uint8_t code, uint16_t tid, size_t size);
Variable coap_pdu_t
coap_pdu_t *coap_new_pdu(const struct coap_session_t *session);
Consts
Const
const char *coap_response_phrase(unsigned char code);
Types
Typedefs
Typedef coap_tid_t
typedef int coap_tid_t;
Typedef coap_pdu_t;
typedef struct coap_pdu_t {
uint8_t type; /**< message type */
uint8_t code; /**< request method (value 1--10) or response code (value 40-255) */
uint8_t max_hdr_size; /**< space reserved for protocol-specific header */
uint8_t hdr_size; /**< actaul size used for protocol-specific header */
uint8_t token_length; /**< length of Token */
uint16_t tid; /**< transaction id, if any, in regular host byte order */
uint16_t max_delta; /**< highest option number */
size_t alloc_size; /**< allocated storage for token, options and payload */
size_t used_size; /**< used bytes of storage for token, options and payload */
size_t max_size; /**< maximum size for token, options and payload, or zero for variable size pdu */
uint8_t *token; /**< first byte of token, if any, or options */
uint8_t *data; /**< first byte of payload, if any */
#ifdef WITH_LWIP
struct pbuf *pbuf; /**< lwIP PBUF. The package data will always reside
* inside the pbuf's payload, but this pointer
* has to be kept because no exact offset can be
* given. This field must not be accessed from
* outside, because the pbuf's reference count
* is checked to be 1 when the pbuf is assigned
* to the pdu, and the pbuf stays exclusive to
* this pdu. */
#endif
} coap_pdu_t;
Typedef coap_proto_t
typedef uint8_t coap_proto_t;