41#define COAP_DEFAULT_PORT 5683
42#define COAPS_DEFAULT_PORT 5684
43#define COAP_DEFAULT_MAX_AGE 60
44#ifndef COAP_DEFAULT_MTU
45#define COAP_DEFAULT_MTU 1152
48#define COAP_BERT_BASE 1152
50#ifndef COAP_DEFAULT_HOP_LIMIT
51#define COAP_DEFAULT_HOP_LIMIT 16
54#define COAP_DEFAULT_SCHEME "coap"
57#define COAP_DEFAULT_URI_WELLKNOWN ".well-known/core"
60#define COAP_TOKEN_DEFAULT_MAX 8
61#if (UINT_MAX > 65804UL)
62#define COAP_TOKEN_EXT_MAX 65804UL
64#define COAP_TOKEN_EXT_MAX 4096
123#define COAP_OPTION_IF_MATCH 1
124#define COAP_OPTION_URI_HOST 3
125#define COAP_OPTION_ETAG 4
126#define COAP_OPTION_IF_NONE_MATCH 5
127#define COAP_OPTION_OBSERVE 6
128#define COAP_OPTION_URI_PORT 7
129#define COAP_OPTION_LOCATION_PATH 8
130#define COAP_OPTION_OSCORE 9
131#define COAP_OPTION_URI_PATH 11
132#define COAP_OPTION_CONTENT_FORMAT 12
133#define COAP_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
135#define COAP_OPTION_MAXAGE 14
136#define COAP_OPTION_URI_QUERY 15
137#define COAP_OPTION_HOP_LIMIT 16
138#define COAP_OPTION_ACCEPT 17
139#define COAP_OPTION_Q_BLOCK1 19
140#define COAP_OPTION_LOCATION_QUERY 20
141#define COAP_OPTION_EDHOC 21
142#define COAP_OPTION_BLOCK2 23
143#define COAP_OPTION_BLOCK1 27
144#define COAP_OPTION_SIZE2 28
145#define COAP_OPTION_Q_BLOCK2 31
146#define COAP_OPTION_PROXY_URI 35
147#define COAP_OPTION_PROXY_SCHEME 39
148#define COAP_OPTION_SIZE1 60
149#define COAP_OPTION_ECHO 252
150#define COAP_OPTION_NORESPONSE 258
151#define COAP_OPTION_RTAG 292
153#if (UINT_MAX > 65535)
154#define COAP_MAX_OPT 65535
156#define COAP_MAX_OPT 65534
165#define COAP_RESPONSE_CODE(N) (((N)/100 << 5) | (N)%100)
168#define COAP_RESPONSE_CLASS(C) (((C) >> 5) & 0xFF)
170#ifndef SHORT_ERROR_RESPONSE
183#define COAP_ERROR_PHRASE_LENGTH 32
186#define coap_response_phrase(x) ((char *)NULL)
188#define COAP_ERROR_PHRASE_LENGTH 0
191#define COAP_SIGNALING_CODE(N) (((N)/100 << 5) | (N)%100)
202#define COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE 2
203#define COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER 4
204#define COAP_SIGNALING_OPTION_EXTENDED_TOKEN_LENGTH 6
207#define COAP_SIGNALING_OPTION_CUSTODY 2
210#define COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS 2
211#define COAP_SIGNALING_OPTION_HOLD_OFF 4
214#define COAP_SIGNALING_OPTION_BAD_CSM_OPTION 2
218#define COAP_MEDIATYPE_TEXT_PLAIN 0
219#define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT 40
220#define COAP_MEDIATYPE_APPLICATION_XML 41
221#define COAP_MEDIATYPE_APPLICATION_OCTET_STREAM 42
222#define COAP_MEDIATYPE_APPLICATION_RDF_XML 43
223#define COAP_MEDIATYPE_APPLICATION_EXI 47
224#define COAP_MEDIATYPE_APPLICATION_JSON 50
225#define COAP_MEDIATYPE_APPLICATION_CBOR 60
226#define COAP_MEDIATYPE_APPLICATION_CWT 61
229#define COAP_MEDIATYPE_APPLICATION_COAP_GROUP_JSON 256
232#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN 98
233#define COAP_MEDIATYPE_APPLICATION_COSE_SIGN1 18
234#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT 96
235#define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0 16
236#define COAP_MEDIATYPE_APPLICATION_COSE_MAC 97
237#define COAP_MEDIATYPE_APPLICATION_COSE_MAC0 17
239#define COAP_MEDIATYPE_APPLICATION_COSE_KEY 101
240#define COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET 102
243#define COAP_MEDIATYPE_APPLICATION_SENML_JSON 110
244#define COAP_MEDIATYPE_APPLICATION_SENSML_JSON 111
245#define COAP_MEDIATYPE_APPLICATION_SENML_CBOR 112
246#define COAP_MEDIATYPE_APPLICATION_SENSML_CBOR 113
247#define COAP_MEDIATYPE_APPLICATION_SENML_EXI 114
248#define COAP_MEDIATYPE_APPLICATION_SENSML_EXI 115
249#define COAP_MEDIATYPE_APPLICATION_SENML_XML 310
250#define COAP_MEDIATYPE_APPLICATION_SENSML_XML 311
253#define COAP_MEDIATYPE_APPLICATION_DOTS_CBOR 271
256#define COAP_MEDIATYPE_APPLICATION_ACE_CBOR 19
259#define COAP_MEDIATYPE_APPLICATION_MB_CBOR_SEQ 272
262#define COAP_MEDIATYPE_APPLICATION_OSCORE 10001
271#define COAP_INVALID_MID -1
277#define COAP_INVALID_TID COAP_INVALID_MID
291#define COAP_OPTION_KEY(option) (option).key
292#define COAP_OPTION_LENGTH(option) (option).length
293#define COAP_OPTION_DATA(option) ((unsigned char *)&(option) + sizeof(coap_option))
311coap_pdu_t *coap_pdu_from_pbuf(
struct pbuf *pbuf);
438 const uint8_t *token,
476 const uint8_t *data);
502 const uint8_t *data);
517 const uint8_t *data);
547 const uint8_t **data);
568 const uint8_t **data,
Helpers for handling options in CoAP PDUs.
uint16_t coap_option_num_t
Helper functions for URI treatment.
coap_pdu_code_t coap_pdu_get_code(const coap_pdu_t *pdu)
Gets the PDU code associated with pdu.
const char * coap_response_phrase(unsigned char code)
Returns a human-readable response phrase for the specified CoAP response code.
COAP_API void coap_delete_pdu(coap_pdu_t *pdu)
Dispose of an CoAP PDU and free off associated storage.
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.
void coap_pdu_set_code(coap_pdu_t *pdu, coap_pdu_code_t code)
Sets the PDU code in the pdu.
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
COAP_API 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.
coap_request_t
CoAP PDU Request methods.
#define COAP_RESPONSE_CODE(N)
#define COAP_SIGNALING_CODE(N)
coap_proto_t
CoAP protocol types.
coap_pdu_code_t
Set of codes available for a PDU.
coap_pdu_type_t
CoAP PDU message type definitions.
int coap_add_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds token of length len to pdu.
void coap_pdu_set_type(coap_pdu_t *pdu, coap_pdu_type_t type)
Sets the PDU type in the pdu.
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.
coap_pdu_signaling_proto_t
coap_pdu_type_t coap_pdu_get_type(const coap_pdu_t *pdu)
Gets the PDU type associated with pdu.
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.
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.
void coap_pdu_set_mid(coap_pdu_t *pdu, coap_mid_t mid)
Sets the message id in the pdu.
COAP_API 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.
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.
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.
coap_mid_t coap_pdu_get_mid(const coap_pdu_t *pdu)
Gets the message id associated with pdu.
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.
coap_bin_const_t coap_pdu_get_token(const coap_pdu_t *pdu)
Gets the token associated with pdu.
@ COAP_RESPONSE_CODE_INTERNAL_ERROR
@ COAP_RESPONSE_CODE_HOP_LIMIT_REACHED
@ COAP_SIGNALING_CODE_ABORT
@ COAP_RESPONSE_CODE_PRECONDITION_FAILED
@ COAP_RESPONSE_CODE_NOT_ALLOWED
@ COAP_RESPONSE_CODE_CHANGED
@ COAP_RESPONSE_CODE_NOT_ACCEPTABLE
@ COAP_SIGNALING_CODE_CSM
@ COAP_REQUEST_CODE_PATCH
@ COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED
@ COAP_RESPONSE_CODE_BAD_REQUEST
@ COAP_SIGNALING_CODE_PING
@ COAP_RESPONSE_CODE_INCOMPLETE
@ COAP_REQUEST_CODE_DELETE
@ COAP_SIGNALING_CODE_PONG
@ COAP_RESPONSE_CODE_NOT_IMPLEMENTED
@ COAP_RESPONSE_CODE_NOT_FOUND
@ COAP_RESPONSE_CODE_BAD_GATEWAY
@ COAP_RESPONSE_CODE_BAD_OPTION
@ COAP_RESPONSE_CODE_REQUEST_TOO_LARGE
@ COAP_RESPONSE_CODE_TOO_MANY_REQUESTS
@ COAP_RESPONSE_CODE_CONFLICT
@ COAP_RESPONSE_CODE_DELETED
@ COAP_RESPONSE_CODE_UNAUTHORIZED
@ COAP_RESPONSE_CODE_CREATED
@ COAP_RESPONSE_CODE_CONTENT
@ COAP_RESPONSE_CODE_UNPROCESSABLE
@ COAP_RESPONSE_CODE_CONTINUE
@ COAP_RESPONSE_CODE_VALID
@ COAP_RESPONSE_CODE_UNSUPPORTED_CONTENT_FORMAT
@ COAP_SIGNALING_CODE_RELEASE
@ COAP_REQUEST_CODE_FETCH
@ COAP_RESPONSE_CODE_GATEWAY_TIMEOUT
@ COAP_REQUEST_CODE_IPATCH
@ COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE
@ COAP_RESPONSE_CODE_FORBIDDEN
CoAP binary data definition with const data.
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...