Contiki-NG
coap-constants.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  */
31 
32 /**
33  * \file
34  * Collection of constants specified in the CoAP standard.
35  * \author
36  * Matthias Kovatsch <kovatsch@inf.ethz.ch>
37  */
38 
39 /**
40  * \addtogroup coap
41  * @{
42  */
43 
44 #ifndef COAP_CONSTANTS_H_
45 #define COAP_CONSTANTS_H_
46 
47 #define COAP_DEFAULT_PORT 5683
48 #define COAP_DEFAULT_SECURE_PORT 5684
49 
50 #define COAP_DEFAULT_MAX_AGE 60
51 #define COAP_RESPONSE_TIMEOUT 3
52 #define COAP_RESPONSE_RANDOM_FACTOR 1.5
53 #define COAP_MAX_RETRANSMIT 4
54 
55 #define COAP_HEADER_LEN 4 /* | version:0x03 type:0x0C tkl:0xF0 | code | mid:0x00FF | mid:0xFF00 | */
56 #define COAP_TOKEN_LEN 8 /* The maximum number of bytes for the Token */
57 #define COAP_ETAG_LEN 8 /* The maximum number of bytes for the ETag */
58 
59 #define COAP_HEADER_VERSION_MASK 0xC0
60 #define COAP_HEADER_VERSION_POSITION 6
61 #define COAP_HEADER_TYPE_MASK 0x30
62 #define COAP_HEADER_TYPE_POSITION 4
63 #define COAP_HEADER_TOKEN_LEN_MASK 0x0F
64 #define COAP_HEADER_TOKEN_LEN_POSITION 0
65 
66 #define COAP_HEADER_OPTION_DELTA_MASK 0xF0
67 #define COAP_HEADER_OPTION_SHORT_LENGTH_MASK 0x0F
68 
69 /* CoAP message types */
70 typedef enum {
71  COAP_TYPE_CON, /* confirmables */
72  COAP_TYPE_NON, /* non-confirmables */
73  COAP_TYPE_ACK, /* acknowledgements */
74  COAP_TYPE_RST /* reset */
75 } coap_message_type_t;
76 
77 /* CoAP request method codes */
78 typedef enum {
79  COAP_GET = 1,
80  COAP_POST,
81  COAP_PUT,
82  COAP_DELETE
83 } coap_method_t;
84 
85 /* CoAP response codes */
86 typedef enum {
87  NO_ERROR = 0,
88 
89  CREATED_2_01 = 65, /* CREATED */
90  DELETED_2_02 = 66, /* DELETED */
91  VALID_2_03 = 67, /* NOT_MODIFIED */
92  CHANGED_2_04 = 68, /* CHANGED */
93  CONTENT_2_05 = 69, /* OK */
94  CONTINUE_2_31 = 95, /* CONTINUE */
95 
96  BAD_REQUEST_4_00 = 128, /* BAD_REQUEST */
97  UNAUTHORIZED_4_01 = 129, /* UNAUTHORIZED */
98  BAD_OPTION_4_02 = 130, /* BAD_OPTION */
99  FORBIDDEN_4_03 = 131, /* FORBIDDEN */
100  NOT_FOUND_4_04 = 132, /* NOT_FOUND */
101  METHOD_NOT_ALLOWED_4_05 = 133, /* METHOD_NOT_ALLOWED */
102  NOT_ACCEPTABLE_4_06 = 134, /* NOT_ACCEPTABLE */
103  PRECONDITION_FAILED_4_12 = 140, /* BAD_REQUEST */
104  REQUEST_ENTITY_TOO_LARGE_4_13 = 141, /* REQUEST_ENTITY_TOO_LARGE */
105  UNSUPPORTED_MEDIA_TYPE_4_15 = 143, /* UNSUPPORTED_MEDIA_TYPE */
106 
107  INTERNAL_SERVER_ERROR_5_00 = 160, /* INTERNAL_SERVER_ERROR */
108  NOT_IMPLEMENTED_5_01 = 161, /* NOT_IMPLEMENTED */
109  BAD_GATEWAY_5_02 = 162, /* BAD_GATEWAY */
110  SERVICE_UNAVAILABLE_5_03 = 163, /* SERVICE_UNAVAILABLE */
111  GATEWAY_TIMEOUT_5_04 = 164, /* GATEWAY_TIMEOUT */
112  PROXYING_NOT_SUPPORTED_5_05 = 165, /* PROXYING_NOT_SUPPORTED */
113 
114  /* Erbium errors */
115  MEMORY_ALLOCATION_ERROR = 192,
116  PACKET_SERIALIZATION_ERROR,
117 
118  /* Erbium hooks */
119  MANUAL_RESPONSE,
120  PING_RESPONSE
121 } coap_status_t;
122 
123 /* CoAP header option numbers */
124 typedef enum {
125  COAP_OPTION_IF_MATCH = 1, /* 0-8 B */
126  COAP_OPTION_URI_HOST = 3, /* 1-255 B */
127  COAP_OPTION_ETAG = 4, /* 1-8 B */
128  COAP_OPTION_IF_NONE_MATCH = 5, /* 0 B */
129  COAP_OPTION_OBSERVE = 6, /* 0-3 B */
130  COAP_OPTION_URI_PORT = 7, /* 0-2 B */
131  COAP_OPTION_LOCATION_PATH = 8, /* 0-255 B */
132  COAP_OPTION_URI_PATH = 11, /* 0-255 B */
133  COAP_OPTION_CONTENT_FORMAT = 12, /* 0-2 B */
134  COAP_OPTION_MAX_AGE = 14, /* 0-4 B */
135  COAP_OPTION_URI_QUERY = 15, /* 0-255 B */
136  COAP_OPTION_ACCEPT = 17, /* 0-2 B */
137  COAP_OPTION_LOCATION_QUERY = 20, /* 0-255 B */
138  COAP_OPTION_BLOCK2 = 23, /* 1-3 B */
139  COAP_OPTION_BLOCK1 = 27, /* 1-3 B */
140  COAP_OPTION_SIZE2 = 28, /* 0-4 B */
141  COAP_OPTION_PROXY_URI = 35, /* 1-1034 B */
142  COAP_OPTION_PROXY_SCHEME = 39, /* 1-255 B */
143  COAP_OPTION_SIZE1 = 60, /* 0-4 B */
144 } coap_option_t;
145 
146 /* CoAP Content-Formats */
147 typedef enum {
148  TEXT_PLAIN = 0,
149  TEXT_XML = 1,
150  TEXT_CSV = 2,
151  TEXT_HTML = 3,
152  IMAGE_GIF = 21,
153  IMAGE_JPEG = 22,
154  IMAGE_PNG = 23,
155  IMAGE_TIFF = 24,
156  AUDIO_RAW = 25,
157  VIDEO_RAW = 26,
158  APPLICATION_LINK_FORMAT = 40,
159  APPLICATION_XML = 41,
160  APPLICATION_OCTET_STREAM = 42,
161  APPLICATION_RDF_XML = 43,
162  APPLICATION_SOAP_XML = 44,
163  APPLICATION_ATOM_XML = 45,
164  APPLICATION_XMPP_XML = 46,
165  APPLICATION_EXI = 47,
166  APPLICATION_FASTINFOSET = 48,
167  APPLICATION_SOAP_FASTINFOSET = 49,
168  APPLICATION_JSON = 50,
169  APPLICATION_X_OBIX_BINARY = 51
170 } coap_content_format_t;
171 
172 /**
173  * Resource flags for allowed methods and special functionalities.
174  */
175 typedef enum {
176  NO_FLAGS = 0,
177 
178  /* methods to handle */
179  METHOD_GET = (1 << 0),
180  METHOD_POST = (1 << 1),
181  METHOD_PUT = (1 << 2),
182  METHOD_DELETE = (1 << 3),
183 
184  /* special flags */
185  HAS_SUB_RESOURCES = (1 << 4),
186  IS_SEPARATE = (1 << 5),
187  IS_OBSERVABLE = (1 << 6),
188  IS_PERIODIC = (1 << 7)
190 
191 #endif /* COAP_CONSTANTS_H_ */
192 /** @} */
coap_resource_flags_t
Resource flags for allowed methods and special functionalities.