Contiki 3.x
er-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 #ifndef ER_COAP_CONSTANTS_H_
40 #define ER_COAP_CONSTANTS_H_
41 
42 #define COAP_DEFAULT_PORT 5683
43 
44 #define COAP_DEFAULT_MAX_AGE 60
45 #define COAP_RESPONSE_TIMEOUT 3
46 #define COAP_RESPONSE_RANDOM_FACTOR 1.5
47 #define COAP_MAX_RETRANSMIT 4
48 
49 #define COAP_HEADER_LEN 4 /* | version:0x03 type:0x0C tkl:0xF0 | code | mid:0x00FF | mid:0xFF00 | */
50 #define COAP_TOKEN_LEN 8 /* The maximum number of bytes for the Token */
51 #define COAP_ETAG_LEN 8 /* The maximum number of bytes for the ETag */
52 
53 #define COAP_HEADER_VERSION_MASK 0xC0
54 #define COAP_HEADER_VERSION_POSITION 6
55 #define COAP_HEADER_TYPE_MASK 0x30
56 #define COAP_HEADER_TYPE_POSITION 4
57 #define COAP_HEADER_TOKEN_LEN_MASK 0x0F
58 #define COAP_HEADER_TOKEN_LEN_POSITION 0
59 
60 #define COAP_HEADER_OPTION_DELTA_MASK 0xF0
61 #define COAP_HEADER_OPTION_SHORT_LENGTH_MASK 0x0F
62 
63 /* CoAP message types */
64 typedef enum {
65  COAP_TYPE_CON, /* confirmables */
66  COAP_TYPE_NON, /* non-confirmables */
67  COAP_TYPE_ACK, /* acknowledgements */
68  COAP_TYPE_RST /* reset */
69 } coap_message_type_t;
70 
71 /* CoAP request method codes */
72 typedef enum {
73  COAP_GET = 1,
74  COAP_POST,
75  COAP_PUT,
76  COAP_DELETE
77 } coap_method_t;
78 
79 /* CoAP response codes */
80 typedef enum {
81  NO_ERROR = 0,
82 
83  CREATED_2_01 = 65, /* CREATED */
84  DELETED_2_02 = 66, /* DELETED */
85  VALID_2_03 = 67, /* NOT_MODIFIED */
86  CHANGED_2_04 = 68, /* CHANGED */
87  CONTENT_2_05 = 69, /* OK */
88  CONTINUE_2_31 = 95, /* CONTINUE */
89 
90  BAD_REQUEST_4_00 = 128, /* BAD_REQUEST */
91  UNAUTHORIZED_4_01 = 129, /* UNAUTHORIZED */
92  BAD_OPTION_4_02 = 130, /* BAD_OPTION */
93  FORBIDDEN_4_03 = 131, /* FORBIDDEN */
94  NOT_FOUND_4_04 = 132, /* NOT_FOUND */
95  METHOD_NOT_ALLOWED_4_05 = 133, /* METHOD_NOT_ALLOWED */
96  NOT_ACCEPTABLE_4_06 = 134, /* NOT_ACCEPTABLE */
97  PRECONDITION_FAILED_4_12 = 140, /* BAD_REQUEST */
98  REQUEST_ENTITY_TOO_LARGE_4_13 = 141, /* REQUEST_ENTITY_TOO_LARGE */
99  UNSUPPORTED_MEDIA_TYPE_4_15 = 143, /* UNSUPPORTED_MEDIA_TYPE */
100 
101  INTERNAL_SERVER_ERROR_5_00 = 160, /* INTERNAL_SERVER_ERROR */
102  NOT_IMPLEMENTED_5_01 = 161, /* NOT_IMPLEMENTED */
103  BAD_GATEWAY_5_02 = 162, /* BAD_GATEWAY */
104  SERVICE_UNAVAILABLE_5_03 = 163, /* SERVICE_UNAVAILABLE */
105  GATEWAY_TIMEOUT_5_04 = 164, /* GATEWAY_TIMEOUT */
106  PROXYING_NOT_SUPPORTED_5_05 = 165, /* PROXYING_NOT_SUPPORTED */
107 
108  /* Erbium errors */
109  MEMORY_ALLOCATION_ERROR = 192,
110  PACKET_SERIALIZATION_ERROR,
111 
112  /* Erbium hooks */
113  MANUAL_RESPONSE,
114  PING_RESPONSE
115 } coap_status_t;
116 
117 /* CoAP header option numbers */
118 typedef enum {
119  COAP_OPTION_IF_MATCH = 1, /* 0-8 B */
120  COAP_OPTION_URI_HOST = 3, /* 1-255 B */
121  COAP_OPTION_ETAG = 4, /* 1-8 B */
122  COAP_OPTION_IF_NONE_MATCH = 5, /* 0 B */
123  COAP_OPTION_OBSERVE = 6, /* 0-3 B */
124  COAP_OPTION_URI_PORT = 7, /* 0-2 B */
125  COAP_OPTION_LOCATION_PATH = 8, /* 0-255 B */
126  COAP_OPTION_URI_PATH = 11, /* 0-255 B */
127  COAP_OPTION_CONTENT_FORMAT = 12, /* 0-2 B */
128  COAP_OPTION_MAX_AGE = 14, /* 0-4 B */
129  COAP_OPTION_URI_QUERY = 15, /* 0-255 B */
130  COAP_OPTION_ACCEPT = 17, /* 0-2 B */
131  COAP_OPTION_LOCATION_QUERY = 20, /* 0-255 B */
132  COAP_OPTION_BLOCK2 = 23, /* 1-3 B */
133  COAP_OPTION_BLOCK1 = 27, /* 1-3 B */
134  COAP_OPTION_SIZE2 = 28, /* 0-4 B */
135  COAP_OPTION_PROXY_URI = 35, /* 1-1034 B */
136  COAP_OPTION_PROXY_SCHEME = 39, /* 1-255 B */
137  COAP_OPTION_SIZE1 = 60, /* 0-4 B */
138 } coap_option_t;
139 
140 /* CoAP Content-Formats */
141 typedef enum {
142  TEXT_PLAIN = 0,
143  TEXT_XML = 1,
144  TEXT_CSV = 2,
145  TEXT_HTML = 3,
146  IMAGE_GIF = 21,
147  IMAGE_JPEG = 22,
148  IMAGE_PNG = 23,
149  IMAGE_TIFF = 24,
150  AUDIO_RAW = 25,
151  VIDEO_RAW = 26,
152  APPLICATION_LINK_FORMAT = 40,
153  APPLICATION_XML = 41,
154  APPLICATION_OCTET_STREAM = 42,
155  APPLICATION_RDF_XML = 43,
156  APPLICATION_SOAP_XML = 44,
157  APPLICATION_ATOM_XML = 45,
158  APPLICATION_XMPP_XML = 46,
159  APPLICATION_EXI = 47,
160  APPLICATION_FASTINFOSET = 48,
161  APPLICATION_SOAP_FASTINFOSET = 49,
162  APPLICATION_JSON = 50,
163  APPLICATION_X_OBIX_BINARY = 51
164 } coap_content_format_t;
165 
166 #endif /* ER_COAP_CONSTANTS_H_ */