24 #include <lwip/pbuf.h>
35 #define COAP_DEFAULT_PORT 5683
36 #define COAPS_DEFAULT_PORT 5684
37 #define COAP_DEFAULT_MAX_AGE 60
38 #ifndef COAP_DEFAULT_MTU
39 #define COAP_DEFAULT_MTU 1152
42 #ifndef COAP_DEFAULT_HOP_LIMIT
43 #define COAP_DEFAULT_HOP_LIMIT 16
46 #define COAP_DEFAULT_SCHEME "coap"
49 #define COAP_DEFAULT_URI_WELLKNOWN ".well-known/core"
107 #define COAP_OPTION_IF_MATCH 1
108 #define COAP_OPTION_URI_HOST 3
109 #define COAP_OPTION_ETAG 4
110 #define COAP_OPTION_IF_NONE_MATCH 5
111 #define COAP_OPTION_OBSERVE 6
112 #define COAP_OPTION_URI_PORT 7
113 #define COAP_OPTION_LOCATION_PATH 8
114 #define COAP_OPTION_OSCORE 9
115 #define COAP_OPTION_URI_PATH 11
116 #define COAP_OPTION_CONTENT_FORMAT 12
117 #define COAP_OPTION_CONTENT_TYPE COAP_OPTION_CONTENT_FORMAT
119 #define COAP_OPTION_MAXAGE 14
120 #define COAP_OPTION_URI_QUERY 15
121 #define COAP_OPTION_HOP_LIMIT 16
122 #define COAP_OPTION_ACCEPT 17
123 #define COAP_OPTION_LOCATION_QUERY 20
124 #define COAP_OPTION_BLOCK2 23
125 #define COAP_OPTION_BLOCK1 27
126 #define COAP_OPTION_SIZE2 28
127 #define COAP_OPTION_PROXY_URI 35
128 #define COAP_OPTION_PROXY_SCHEME 39
129 #define COAP_OPTION_SIZE1 60
130 #define COAP_OPTION_NORESPONSE 258
132 #define COAP_MAX_OPT 65535
140 #define COAP_RESPONSE_CODE(N) (((N)/100 << 5) | (N)%100)
143 #define COAP_RESPONSE_CLASS(C) (((C) >> 5) & 0xFF)
145 #ifndef SHORT_ERROR_RESPONSE
158 #define COAP_ERROR_PHRASE_LENGTH 32
161 #define coap_response_phrase(x) ((char *)NULL)
163 #define COAP_ERROR_PHRASE_LENGTH 0
166 #define COAP_SIGNALING_CODE(N) (((N)/100 << 5) | (N)%100)
177 #define COAP_SIGNALING_OPTION_MAX_MESSAGE_SIZE 2
178 #define COAP_SIGNALING_OPTION_BLOCK_WISE_TRANSFER 4
180 #define COAP_SIGNALING_OPTION_CUSTODY 2
182 #define COAP_SIGNALING_OPTION_ALTERNATIVE_ADDRESS 2
183 #define COAP_SIGNALING_OPTION_HOLD_OFF 4
185 #define COAP_SIGNALING_OPTION_BAD_CSM_OPTION 2
189 #define COAP_MEDIATYPE_TEXT_PLAIN 0
190 #define COAP_MEDIATYPE_APPLICATION_LINK_FORMAT 40
191 #define COAP_MEDIATYPE_APPLICATION_XML 41
192 #define COAP_MEDIATYPE_APPLICATION_OCTET_STREAM 42
193 #define COAP_MEDIATYPE_APPLICATION_RDF_XML 43
194 #define COAP_MEDIATYPE_APPLICATION_EXI 47
195 #define COAP_MEDIATYPE_APPLICATION_JSON 50
196 #define COAP_MEDIATYPE_APPLICATION_CBOR 60
197 #define COAP_MEDIATYPE_APPLICATION_CWT 61
200 #define COAP_MEDIATYPE_APPLICATION_COSE_SIGN 98
201 #define COAP_MEDIATYPE_APPLICATION_COSE_SIGN1 18
202 #define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT 96
203 #define COAP_MEDIATYPE_APPLICATION_COSE_ENCRYPT0 16
204 #define COAP_MEDIATYPE_APPLICATION_COSE_MAC 97
205 #define COAP_MEDIATYPE_APPLICATION_COSE_MAC0 17
207 #define COAP_MEDIATYPE_APPLICATION_COSE_KEY 101
208 #define COAP_MEDIATYPE_APPLICATION_COSE_KEY_SET 102
211 #define COAP_MEDIATYPE_APPLICATION_SENML_JSON 110
212 #define COAP_MEDIATYPE_APPLICATION_SENSML_JSON 111
213 #define COAP_MEDIATYPE_APPLICATION_SENML_CBOR 112
214 #define COAP_MEDIATYPE_APPLICATION_SENSML_CBOR 113
215 #define COAP_MEDIATYPE_APPLICATION_SENML_EXI 114
216 #define COAP_MEDIATYPE_APPLICATION_SENSML_EXI 115
217 #define COAP_MEDIATYPE_APPLICATION_SENML_XML 310
218 #define COAP_MEDIATYPE_APPLICATION_SENSML_XML 311
221 #define COAP_MEDIATYPE_APPLICATION_DOTS_CBOR 271
225 #define COAP_MEDIATYPE_ANY 0xff
234 #define COAP_INVALID_MID -1
240 #define COAP_INVALID_TID COAP_INVALID_MID
254 #define COAP_OPTION_KEY(option) (option).key
255 #define COAP_OPTION_LENGTH(option) (option).length
256 #define COAP_OPTION_DATA(option) ((unsigned char *)&(option) + sizeof(coap_option))
274 coap_pdu_t * coap_pdu_from_pbuf(
struct pbuf *pbuf);
395 const uint8_t *token,
413 const uint8_t *data);
439 const uint8_t *data);
454 const uint8_t *data);
484 const uint8_t **data);
505 const uint8_t **data,
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 copy it.
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.
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
Helpers for handling options in CoAP PDUs.
uint16_t coap_option_num_t
CoAP binary data definition with const data.
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...