coap.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2018 Freie Universität Berlin
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
28 #define COAP_PORT (5683)
29 
33 #define COAPS_PORT (5684)
34 
35 #define COAP_V1 (1)
41 #define COAP_OPT_IF_MATCH (1)
42 #define COAP_OPT_URI_HOST (3)
43 #define COAP_OPT_ETAG (4)
44 #define COAP_OPT_IF_NONE_MATCH (5)
45 #define COAP_OPT_OBSERVE (6)
46 #define COAP_OPT_LOCATION_PATH (8)
55 #define COAP_OPT_OSCORE (9)
56 #define COAP_OPT_URI_PATH (11)
57 #define COAP_OPT_CONTENT_FORMAT (12)
58 #define COAP_OPT_MAX_AGE (14)
59 #define COAP_OPT_URI_QUERY (15)
67 #define COAP_OPT_HOP_LIMIT (16)
68 #define COAP_OPT_ACCEPT (17)
76 #define COAP_OPT_Q_BLOCK1 (19)
77 #define COAP_OPT_LOCATION_QUERY (20)
86 #define COAP_OPT_EDHOC (21)
87 #define COAP_OPT_BLOCK2 (23)
88 #define COAP_OPT_BLOCK1 (27)
99 #define COAP_OPT_SIZE2 (28)
107 #define COAP_OPT_Q_BLOCK2 (31)
108 #define COAP_OPT_PROXY_URI (35)
109 #define COAP_OPT_PROXY_SCHEME (39)
122 #define COAP_OPT_SIZE1 (60)
131 #define COAP_OPT_ECHO (252)
136 #define COAP_OPT_NO_RESPONSE (258)
145 #define COAP_OPT_REQUEST_TAG (292)
152 #define COAP_TYPE_CON (0)
153 #define COAP_TYPE_NON (1)
154 #define COAP_TYPE_ACK (2)
155 #define COAP_TYPE_RST (3)
162 #define COAP_CLASS_REQ (0)
167 typedef enum {
175 } coap_method_t;
182 #define COAP_CODE_EMPTY (0)
189 #define COAP_CLASS_SUCCESS (2)
190 #define COAP_CODE_CREATED ((2 << 5) | 1)
191 #define COAP_CODE_DELETED ((2 << 5) | 2)
192 #define COAP_CODE_VALID ((2 << 5) | 3)
193 #define COAP_CODE_CHANGED ((2 << 5) | 4)
194 #define COAP_CODE_204 ((2 << 5) | 4)
195 #define COAP_CODE_CONTENT ((2 << 5) | 5)
196 #define COAP_CODE_205 ((2 << 5) | 5)
197 #define COAP_CODE_CONTINUE ((2 << 5) | 31)
198 #define COAP_CODE_231 ((2 << 5) | 31)
205 #define COAP_CLASS_CLIENT_FAILURE (4)
206 #define COAP_CODE_BAD_REQUEST ((4 << 5) | 0)
207 #define COAP_CODE_UNAUTHORIZED ((4 << 5) | 1)
208 #define COAP_CODE_BAD_OPTION ((4 << 5) | 2)
209 #define COAP_CODE_FORBIDDEN ((4 << 5) | 3)
210 #define COAP_CODE_PATH_NOT_FOUND ((4 << 5) | 4)
211 #define COAP_CODE_404 ((4 << 5) | 4)
212 #define COAP_CODE_METHOD_NOT_ALLOWED ((4 << 5) | 5)
213 #define COAP_CODE_NOT_ACCEPTABLE ((4 << 5) | 6)
214 #define COAP_CODE_REQUEST_ENTITY_INCOMPLETE ((4 << 5) | 8)
215 #define COAP_CODE_CONFLICT ((4 << 5) | 9)
216 #define COAP_CODE_PRECONDITION_FAILED ((4 << 5) | 12)
217 #define COAP_CODE_REQUEST_ENTITY_TOO_LARGE ((4 << 5) | 13)
218 #define COAP_CODE_UNSUPPORTED_CONTENT_FORMAT ((4 << 5) | 15)
219 #define COAP_CODE_UNPROCESSABLE_ENTITY ((4 << 5) | 22)
220 #define COAP_CODE_TOO_MANY_REQUESTS ((4 << 5) | 29)
227 #define COAP_CLASS_SERVER_FAILURE (5)
228 #define COAP_CODE_INTERNAL_SERVER_ERROR ((5 << 5) | 0)
229 #define COAP_CODE_NOT_IMPLEMENTED ((5 << 5) | 1)
230 #define COAP_CODE_BAD_GATEWAY ((5 << 5) | 2)
231 #define COAP_CODE_SERVICE_UNAVAILABLE ((5 << 5) | 3)
232 #define COAP_CODE_GATEWAY_TIMEOUT ((5 << 5) | 4)
233 #define COAP_CODE_PROXYING_NOT_SUPPORTED ((5 << 5) | 5)
241 #define COAP_FORMAT_TEXT (0)
246 #define COAP_FORMAT_COSE_ENCRYPT0 (16)
251 #define COAP_FORMAT_COSE_MAC0 (17)
256 #define COAP_FORMAT_COSE_SIGN1 (18)
261 #define COAP_FORMAT_ACE_CBOR (19)
266 #define COAP_FORMAT_IMAGE_GIF (21)
271 #define COAP_FORMAT_IMAGE_JPEG (22)
276 #define COAP_FORMAT_IMAGE_PNG (23)
277 #define COAP_FORMAT_LINK (40)
278 #define COAP_FORMAT_XML (41)
279 #define COAP_FORMAT_OCTET (42)
280 #define COAP_FORMAT_EXI (47)
281 #define COAP_FORMAT_JSON (50)
282 #define COAP_FORMAT_JSON_PATCH_JSON (51)
283 #define COAP_FORMAT_MERGE_PATCH_JSON (52)
284 #define COAP_FORMAT_CBOR (60)
289 #define COAP_FORMAT_CWT (61)
294 #define COAP_FORMAT_MULTIPART_CORE (62)
299 #define COAP_FORMAT_CBOR_SEQ (63)
304 #define COAP_FORMAT_COSE_ENCRYPT (96)
309 #define COAP_FORMAT_COSE_MAC (97)
314 #define COAP_FORMAT_COSE_SIGN (98)
319 #define COAP_FORMAT_COSE_KEY (101)
324 #define COAP_FORMAT_COSE_KEY_SET (102)
325 #define COAP_FORMAT_SENML_JSON (110)
326 #define COAP_FORMAT_SENSML_JSON (111)
327 #define COAP_FORMAT_SENML_CBOR (112)
328 #define COAP_FORMAT_SENSML_CBOR (113)
329 #define COAP_FORMAT_SENML_EXI (114)
330 #define COAP_FORMAT_SENSML_EXI (115)
335 #define COAP_FORMAT_YANG_DATA_CBOR_SID (140)
340 #define COAP_FORMAT_COAP_GROUP_JSON (256)
345 #define COAP_FORMAT_PROBLEM_DETAILS_CBOR (257)
350 #define COAP_FORMAT_SWID_CBOR (258)
356 #define COAP_FORMAT_PKIXCMP (259)
361 #define COAP_FORMAT_DOTS_CBOR (271)
366 #define COAP_FORMAT_MISSING_BLOCKS_CBOR_SEQ (272)
373 #define COAP_FORMAT_PKCS7_MIME_SERVER_GEN (280)
379 #define COAP_FORMAT_PKCS7_MIME_CERTS_ONLY (281)
386 #define COAP_FORMAT_PKCS8 (284)
392 #define COAP_FORMAT_CSRATTRS (285)
399 #define COAP_FORMAT_PKCS10 (286)
405 #define COAP_FORMAT_PKIX_CERT (287)
410 #define COAP_FORMAT_AIF_CBOR (290)
415 #define COAP_FORMAT_AIF_JSON (291)
416 #define COAP_FORMAT_SENML_XML (310)
417 #define COAP_FORMAT_SENSML_XML (311)
422 #define COAP_FORMAT_SNML_ETCH_JSON (320)
427 #define COAP_FORMAT_SNML_ETCH_CBOR (322)
432 #define COAP_FORMAT_YAML_DATA_CBOR (340)
437 #define COAP_FORMAT_YAML_DATA_CBOR_ID_NAME (341)
442 #define COAP_FORMAT_TD_JSON (432)
447 #define COAP_FORMAT_TM_JSON (433)
452 #define COAP_FORMAT_DNS_MESSAGE (553)
458 #define COAP_FORMAT_VOUCER_COSE_CBOR (836)
462 #define COAP_FORMAT_VND_OCF_CBOR (10000)
467 #define COAP_FORMAT_OSCORE (10001)
472 #define COAP_FORMAT_JAVASCRIPT (10002)
478 #define COAP_FORMAT_JSON_DEFLATE (11050)
484 #define COAP_FORMAT_CBOR_DEFLATE (11060)
489 #define COAP_FORMAT_VND_OMA_LWM2M_TLV (11542)
494 #define COAP_FORMAT_VND_OMA_LWM2M_JSON (11543)
499 #define COAP_FORMAT_VND_OMA_LWM2M_CBOR (11544)
504 #define COAP_FORMAT_TEXT_CSS (20000)
509 #define COAP_FORMAT_IMAGE_SVG_XML (30000)
516 #define COAP_OBS_REGISTER (0)
517 #define COAP_OBS_DEREGISTER (1)
518 #define COAP_OBS_MAX_VALUE_MASK (0xffffff)
525 #define COAP_TOKEN_LENGTH_MAX (8)
532 #define COAP_ETAG_LENGTH_MAX (8U)
538 #define COAP_PAYLOAD_MARKER (0xFF)
539 #define COAP_PAYLOAD_MARKER_SIZE (1U)
563 #ifndef CONFIG_COAP_ACK_TIMEOUT_MS
564 #define CONFIG_COAP_ACK_TIMEOUT_MS (2000)
565 #endif
566 
576 #ifndef CONFIG_COAP_RANDOM_FACTOR_1000
577 #define CONFIG_COAP_RANDOM_FACTOR_1000 (1500)
578 #endif
579 
584 #ifndef CONFIG_COAP_SEPARATE_RESPONSE_TIMEOUT_MS
585 #define CONFIG_COAP_SEPARATE_RESPONSE_TIMEOUT_MS (10 * MS_PER_SEC)
586 #endif
587 
589 #ifndef CONFIG_COAP_MAX_RETRANSMIT
590 #define CONFIG_COAP_MAX_RETRANSMIT (4)
591 #endif
599 #define COAP_NSTART (1)
600 #define COAP_DEFAULT_LEISURE (5)
607 #define COAP_BLOCKWISE_NUM_OFF (4)
608 #define COAP_BLOCKWISE_MORE_OFF (3)
609 #define COAP_BLOCKWISE_SZX_MASK (0x07)
610 #define COAP_BLOCKWISE_SZX_MAX (7)
616 typedef enum {
617  COAP_BLOCKSIZE_16 = 0,
618  COAP_BLOCKSIZE_32,
619  COAP_BLOCKSIZE_64,
620  COAP_BLOCKSIZE_128,
621  COAP_BLOCKSIZE_256,
622  COAP_BLOCKSIZE_512,
623  COAP_BLOCKSIZE_1024,
625 
626 #ifdef __cplusplus
627 }
628 #endif
629 
coap_blksize_t
Coap block-wise-transfer size SZX.
Definition: coap.h:616
coap_method_t
CoAP method codes used in request.
Definition: coap.h:167
@ COAP_METHOD_GET
GET request (no paylod)
Definition: coap.h:168
@ COAP_METHOD_IPATCH
iPATCH request (RFC 8132)
Definition: coap.h:174
@ COAP_METHOD_PUT
PUT request (update resource with payload)
Definition: coap.h:170
@ COAP_METHOD_POST
POST request (resource processes payload)
Definition: coap.h:169
@ COAP_METHOD_PATCH
PATCH request (RFC 8132)
Definition: coap.h:173
@ COAP_METHOD_DELETE
DELETE request (no payload, remove resource)
Definition: coap.h:171
@ COAP_METHOD_FETCH
FETCH request (RFC 8132)
Definition: coap.h:172