25 #include <lwip/pbuf.h>
37 #define COAP_DEFAULT_PORT 5683
38 #define COAPS_DEFAULT_PORT 5684
39 #define COAP_DEFAULT_MAX_AGE 60
40 #ifndef COAP_DEFAULT_MTU
41 #define COAP_DEFAULT_MTU 1152
44 #define COAP_BERT_BASE 1152
46 #ifndef COAP_DEFAULT_HOP_LIMIT
47 #define COAP_DEFAULT_HOP_LIMIT 16
50 #define COAP_DEFAULT_SCHEME "coap"
53 #define COAP_DEFAULT_URI_WELLKNOWN ".well-known/core"
111 #define COAP_OPTION_IF_MATCH 1
112 #define COAP_OPTION_URI_HOST 3
113 #define COAP_OPTION_ETAG 4
114 #define COAP_OPTION_IF_NONE_MATCH 5
115 #define COAP_OPTION_OBSERVE 6
116 #define COAP_OPTION_URI_PORT 7
117 #define COAP_OPTION_LOCATION_PATH 8
118 #define COAP_OPTION_OSCORE 9
119 #define COAP_OPTION_URI_PATH 11
120 #define COAP_OPTION_CONTENT_FORMAT 12
121 #define COAP_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
123 #define COAP_OPTION_MAXAGE 14
124 #define COAP_OPTION_URI_QUERY 15
125 #define COAP_OPTION_HOP_LIMIT 16
126 #define COAP_OPTION_ACCEPT 17
127 #define COAP_OPTION_LOCATION_QUERY 20
128 #define COAP_OPTION_BLOCK2 23
129 #define COAP_OPTION_BLOCK1 27
130 #define COAP_OPTION_SIZE2 28
131 #define COAP_OPTION_PROXY_URI 35
132 #define COAP_OPTION_PROXY_SCHEME 39
133 #define COAP_OPTION_SIZE1 60
134 #define COAP_OPTION_ECHO 252
135 #define COAP_OPTION_NORESPONSE 258
136 #define COAP_OPTION_RTAG 292
138 #define COAP_MAX_OPT 65535
146 #define COAP_RESPONSE_CODE(N) (((N)/100 << 5) | (N)%100)
149 #define COAP_RESPONSE_CLASS(C) (((C) >> 5) & 0xFF)
151 #ifndef SHORT_ERROR_RESPONSE
164 #define COAP_ERROR_PHRASE_LENGTH 32
167 #define coap_response_phrase(x) ((char *)NULL)
169 #define COAP_ERROR_PHRASE_LENGTH 0
172 #define COAP_SIGNALING_CODE(N) (((N)/100 << 5) | (N)%100)
183 #define COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE 2
184 #define COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER 4
186 #define COAP_SIGNALING_OPTION_CUSTODY 2
188 #define COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS 2
189 #define COAP_SIGNALING_OPTION_HOLD_OFF 4
191 #define COAP_SIGNALING_OPTION_BAD_CSM_OPTION 2
195 #define COAP_MEDIATYPE_TEXT_PLAIN 0
196 #define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT 40
197 #define COAP_MEDIATYPE_APPLICATION_XML 41
198 #define COAP_MEDIATYPE_APPLICATION_OCTET_STREAM 42
199 #define COAP_MEDIATYPE_APPLICATION_RDF_XML 43
200 #define COAP_MEDIATYPE_APPLICATION_EXI 47
201 #define COAP_MEDIATYPE_APPLICATION_JSON 50
202 #define COAP_MEDIATYPE_APPLICATION_CBOR 60
203 #define COAP_MEDIATYPE_APPLICATION_CWT 61
206 #define COAP_MEDIATYPE_APPLICATION_COAP_GROUP_JSON 256
209 #define COAP_MEDIATYPE_APPLICATION_COSE_SIGN 98
210 #define COAP_MEDIATYPE_APPLICATION_COSE_SIGN1 18
211 #define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT 96
212 #define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0 16
213 #define COAP_MEDIATYPE_APPLICATION_COSE_MAC 97
214 #define COAP_MEDIATYPE_APPLICATION_COSE_MAC0 17
216 #define COAP_MEDIATYPE_APPLICATION_COSE_KEY 101
217 #define COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET 102
220 #define COAP_MEDIATYPE_APPLICATION_SENML_JSON 110
221 #define COAP_MEDIATYPE_APPLICATION_SENSML_JSON 111
222 #define COAP_MEDIATYPE_APPLICATION_SENML_CBOR 112
223 #define COAP_MEDIATYPE_APPLICATION_SENSML_CBOR 113
224 #define COAP_MEDIATYPE_APPLICATION_SENML_EXI 114
225 #define COAP_MEDIATYPE_APPLICATION_SENSML_EXI 115
226 #define COAP_MEDIATYPE_APPLICATION_SENML_XML 310
227 #define COAP_MEDIATYPE_APPLICATION_SENSML_XML 311
230 #define COAP_MEDIATYPE_APPLICATION_DOTS_CBOR 271
233 #define COAP_MEDIATYPE_APPLICATION_ACE_CBOR 19
237 #define COAP_MEDIATYPE_ANY 0xff
246 #define COAP_INVALID_MID -1
252 #define COAP_INVALID_TID COAP_INVALID_MID
266 #define COAP_OPTION_KEY(option) (option).key
267 #define COAP_OPTION_LENGTH(option) (option).length
268 #define COAP_OPTION_DATA(option) ((unsigned char *)&(option) + sizeof(coap_option))
286 coap_pdu_t * coap_pdu_from_pbuf(
struct pbuf *pbuf);
406 const uint8_t *token,
444 const uint8_t *data);
470 const uint8_t *data);
485 const uint8_t *data);
515 const uint8_t **data);
536 const uint8_t **data,
Helpers for handling options in CoAP PDUs.
uint16_t coap_option_num_t
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_pdu_code_t coap_pdu_get_code(const coap_pdu_t *pdu)
Gets the PDU code associated with pdu.
void coap_delete_pdu(coap_pdu_t *pdu)
Dispose of an CoAP PDU and frees associated storage.
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_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_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_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
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.
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.
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.
const char * coap_response_phrase(unsigned char code)
Returns a human-readable response phrase for the specified CoAP response code.
coap_mid_t coap_pdu_get_mid(const coap_pdu_t *pdu)
Gets the message id associated with 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_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...
Helper functions for URI treatment.