coap.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
22 #ifndef NET_COAP_H
23 #define NET_COAP_H
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
32 #define COAP_PORT (5683)
33 
37 #define COAPS_PORT (5684)
38 
39 #define COAP_V1 (1)
45 #define COAP_OPT_IF_MATCH (1)
46 #define COAP_OPT_URI_HOST (3)
47 #define COAP_OPT_ETAG (4)
48 #define COAP_OPT_IF_NONE_MATCH (5)
49 #define COAP_OPT_OBSERVE (6)
50 #define COAP_OPT_LOCATION_PATH (8)
59 #define COAP_OPT_OSCORE (9)
60 #define COAP_OPT_URI_PATH (11)
61 #define COAP_OPT_CONTENT_FORMAT (12)
62 #define COAP_OPT_MAX_AGE (14)
63 #define COAP_OPT_URI_QUERY (15)
71 #define COAP_OPT_HOP_LIMIT (16)
72 #define COAP_OPT_ACCEPT (17)
80 #define COAP_OPT_Q_BLOCK1 (19)
81 #define COAP_OPT_LOCATION_QUERY (20)
90 #define COAP_OPT_EDHOC (21)
91 #define COAP_OPT_BLOCK2 (23)
92 #define COAP_OPT_BLOCK1 (27)
103 #define COAP_OPT_SIZE2 (28)
111 #define COAP_OPT_Q_BLOCK2 (31)
112 #define COAP_OPT_PROXY_URI (35)
113 #define COAP_OPT_PROXY_SCHEME (39)
126 #define COAP_OPT_SIZE1 (60)
135 #define COAP_OPT_ECHO (252)
140 #define COAP_OPT_NO_RESPONSE (258)
149 #define COAP_OPT_REQUEST_TAG (292)
156 #define COAP_TYPE_CON (0)
157 #define COAP_TYPE_NON (1)
158 #define COAP_TYPE_ACK (2)
159 #define COAP_TYPE_RST (3)
166 #define COAP_CLASS_REQ (0)
171 typedef enum {
179 } coap_method_t;
186 #define COAP_CODE_EMPTY (0)
193 #define COAP_CLASS_SUCCESS (2)
194 #define COAP_CODE_CREATED ((2 << 5) | 1)
195 #define COAP_CODE_DELETED ((2 << 5) | 2)
196 #define COAP_CODE_VALID ((2 << 5) | 3)
197 #define COAP_CODE_CHANGED ((2 << 5) | 4)
198 #define COAP_CODE_204 ((2 << 5) | 4)
199 #define COAP_CODE_CONTENT ((2 << 5) | 5)
200 #define COAP_CODE_205 ((2 << 5) | 5)
201 #define COAP_CODE_CONTINUE ((2 << 5) | 31)
202 #define COAP_CODE_231 ((2 << 5) | 31)
209 #define COAP_CLASS_CLIENT_FAILURE (4)
210 #define COAP_CODE_BAD_REQUEST ((4 << 5) | 0)
211 #define COAP_CODE_UNAUTHORIZED ((4 << 5) | 1)
212 #define COAP_CODE_BAD_OPTION ((4 << 5) | 2)
213 #define COAP_CODE_FORBIDDEN ((4 << 5) | 3)
214 #define COAP_CODE_PATH_NOT_FOUND ((4 << 5) | 4)
215 #define COAP_CODE_404 ((4 << 5) | 4)
216 #define COAP_CODE_METHOD_NOT_ALLOWED ((4 << 5) | 5)
217 #define COAP_CODE_NOT_ACCEPTABLE ((4 << 5) | 6)
218 #define COAP_CODE_REQUEST_ENTITY_INCOMPLETE ((4 << 5) | 8)
219 #define COAP_CODE_CONFLICT ((4 << 5) | 9)
220 #define COAP_CODE_PRECONDITION_FAILED ((4 << 5) | 12)
221 #define COAP_CODE_REQUEST_ENTITY_TOO_LARGE ((4 << 5) | 13)
222 #define COAP_CODE_UNSUPPORTED_CONTENT_FORMAT ((4 << 5) | 15)
223 #define COAP_CODE_UNPROCESSABLE_ENTITY ((4 << 5) | 22)
224 #define COAP_CODE_TOO_MANY_REQUESTS ((4 << 5) | 29)
231 #define COAP_CLASS_SERVER_FAILURE (5)
232 #define COAP_CODE_INTERNAL_SERVER_ERROR ((5 << 5) | 0)
233 #define COAP_CODE_NOT_IMPLEMENTED ((5 << 5) | 1)
234 #define COAP_CODE_BAD_GATEWAY ((5 << 5) | 2)
235 #define COAP_CODE_SERVICE_UNAVAILABLE ((5 << 5) | 3)
236 #define COAP_CODE_GATEWAY_TIMEOUT ((5 << 5) | 4)
237 #define COAP_CODE_PROXYING_NOT_SUPPORTED ((5 << 5) | 5)
245 #define COAP_FORMAT_TEXT (0)
250 #define COAP_FORMAT_COSE_ENCRYPT0 (16)
255 #define COAP_FORMAT_COSE_MAC0 (17)
260 #define COAP_FORMAT_COSE_SIGN1 (18)
265 #define COAP_FORMAT_ACE_CBOR (19)
270 #define COAP_FORMAT_IMAGE_GIF (21)
275 #define COAP_FORMAT_IMAGE_JPEG (22)
280 #define COAP_FORMAT_IMAGE_PNG (23)
281 #define COAP_FORMAT_LINK (40)
282 #define COAP_FORMAT_XML (41)
283 #define COAP_FORMAT_OCTET (42)
284 #define COAP_FORMAT_EXI (47)
285 #define COAP_FORMAT_JSON (50)
286 #define COAP_FORMAT_JSON_PATCH_JSON (51)
287 #define COAP_FORMAT_MERGE_PATCH_JSON (52)
288 #define COAP_FORMAT_CBOR (60)
293 #define COAP_FORMAT_CWT (61)
298 #define COAP_FORMAT_MULTIPART_CORE (62)
303 #define COAP_FORMAT_CBOR_SEQ (63)
308 #define COAP_FORMAT_COSE_ENCRYPT (96)
313 #define COAP_FORMAT_COSE_MAC (97)
318 #define COAP_FORMAT_COSE_SIGN (98)
323 #define COAP_FORMAT_COSE_KEY (101)
328 #define COAP_FORMAT_COSE_KEY_SET (102)
329 #define COAP_FORMAT_SENML_JSON (110)
330 #define COAP_FORMAT_SENSML_JSON (111)
331 #define COAP_FORMAT_SENML_CBOR (112)
332 #define COAP_FORMAT_SENSML_CBOR (113)
333 #define COAP_FORMAT_SENML_EXI (114)
334 #define COAP_FORMAT_SENSML_EXI (115)
339 #define COAP_FORMAT_YANG_DATA_CBOR_SID (140)
344 #define COAP_FORMAT_COAP_GROUP_JSON (256)
349 #define COAP_FORMAT_PROBLEM_DETAILS_CBOR (257)
354 #define COAP_FORMAT_SWID_CBOR (258)
360 #define COAP_FORMAT_PKIXCMP (259)
365 #define COAP_FORMAT_DOTS_CBOR (271)
370 #define COAP_FORMAT_MISSING_BLOCKS_CBOR_SEQ (272)
377 #define COAP_FORMAT_PKCS7_MIME_SERVER_GEN (280)
383 #define COAP_FORMAT_PKCS7_MIME_CERTS_ONLY (281)
390 #define COAP_FORMAT_PKCS8 (284)
396 #define COAP_FORMAT_CSRATTRS (285)
403 #define COAP_FORMAT_PKCS10 (286)
409 #define COAP_FORMAT_PKIX_CERT (287)
414 #define COAP_FORMAT_AIF_CBOR (290)
419 #define COAP_FORMAT_AIF_JSON (291)
420 #define COAP_FORMAT_SENML_XML (310)
421 #define COAP_FORMAT_SENSML_XML (311)
426 #define COAP_FORMAT_SNML_ETCH_JSON (320)
431 #define COAP_FORMAT_SNML_ETCH_CBOR (322)
436 #define COAP_FORMAT_YAML_DATA_CBOR (340)
441 #define COAP_FORMAT_YAML_DATA_CBOR_ID_NAME (341)
446 #define COAP_FORMAT_TD_JSON (432)
451 #define COAP_FORMAT_TM_JSON (433)
456 #define COAP_FORMAT_DNS_MESSAGE (553)
462 #define COAP_FORMAT_VOUCER_COSE_CBOR (836)
466 #define COAP_FORMAT_VND_OCF_CBOR (10000)
471 #define COAP_FORMAT_OSCORE (10001)
476 #define COAP_FORMAT_JAVASCRIPT (10002)
482 #define COAP_FORMAT_JSON_DEFLATE (11050)
488 #define COAP_FORMAT_CBOR_DEFLATE (11060)
493 #define COAP_FORMAT_VND_OMA_LWM2M_TLV (11542)
498 #define COAP_FORMAT_VND_OMA_LWM2M_JSON (11543)
503 #define COAP_FORMAT_VND_OMA_LWM2M_CBOR (11544)
508 #define COAP_FORMAT_TEXT_CSS (20000)
513 #define COAP_FORMAT_IMAGE_SVG_XML (30000)
520 #define COAP_OBS_REGISTER (0)
521 #define COAP_OBS_DEREGISTER (1)
522 #define COAP_OBS_MAX_VALUE_MASK (0xffffff)
529 #define COAP_TOKEN_LENGTH_MAX (8)
536 #define COAP_ETAG_LENGTH_MAX (8U)
542 #define COAP_PAYLOAD_MARKER (0xFF)
543 #define COAP_PAYLOAD_MARKER_SIZE (1U)
567 #ifndef CONFIG_COAP_ACK_TIMEOUT_MS
568 #define CONFIG_COAP_ACK_TIMEOUT_MS (2000)
569 #endif
570 
580 #ifndef CONFIG_COAP_RANDOM_FACTOR_1000
581 #define CONFIG_COAP_RANDOM_FACTOR_1000 (1500)
582 #endif
583 
588 #ifndef CONFIG_COAP_SEPARATE_RESPONSE_TIMEOUT_MS
589 #define CONFIG_COAP_SEPARATE_RESPONSE_TIMEOUT_MS (10 * MS_PER_SEC)
590 #endif
591 
593 #ifndef CONFIG_COAP_MAX_RETRANSMIT
594 #define CONFIG_COAP_MAX_RETRANSMIT (4)
595 #endif
603 #define COAP_NSTART (1)
604 #define COAP_DEFAULT_LEISURE (5)
611 #define COAP_BLOCKWISE_NUM_OFF (4)
612 #define COAP_BLOCKWISE_MORE_OFF (3)
613 #define COAP_BLOCKWISE_SZX_MASK (0x07)
614 #define COAP_BLOCKWISE_SZX_MAX (7)
620 typedef enum {
621  COAP_BLOCKSIZE_16 = 0,
622  COAP_BLOCKSIZE_32,
623  COAP_BLOCKSIZE_64,
624  COAP_BLOCKSIZE_128,
625  COAP_BLOCKSIZE_256,
626  COAP_BLOCKSIZE_512,
627  COAP_BLOCKSIZE_1024,
629 
630 #ifdef __cplusplus
631 }
632 #endif
633 
634 #endif /* NET_COAP_H */
coap_blksize_t
Coap block-wise-transfer size SZX.
Definition: coap.h:620
coap_method_t
CoAP method codes used in request.
Definition: coap.h:171
@ COAP_METHOD_GET
GET request (no paylod)
Definition: coap.h:172
@ COAP_METHOD_IPATCH
iPATCH request (RFC 8132)
Definition: coap.h:178
@ COAP_METHOD_PUT
PUT request (update resource with payload)
Definition: coap.h:174
@ COAP_METHOD_POST
POST request (resource processes payload)
Definition: coap.h:173
@ COAP_METHOD_PATCH
PATCH request (RFC 8132)
Definition: coap.h:177
@ COAP_METHOD_DELETE
DELETE request (no payload, remove resource)
Definition: coap.h:175
@ COAP_METHOD_FETCH
FETCH request (RFC 8132)
Definition: coap.h:176