coap-constants.h 6.7 KB

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