idnits 2.17.1 draft-ietf-core-coap-14.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == Line 4558 has weird spacing: '... Client ff02:...' -- The document date (March 12, 2013) is 4056 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Missing Reference: '0x7d34' is mentioned on line 482, but not defined == Missing Reference: '0x01a0' is mentioned on line 497, but not defined == Missing Reference: '0xbc90' is mentioned on line 539, but not defined == Missing Reference: '0xbc91' is mentioned on line 539, but not defined == Missing Reference: '0x7a10' is mentioned on line 563, but not defined == Missing Reference: '0x23bb' is mentioned on line 574, but not defined == Missing Reference: '0x7a11' is mentioned on line 587, but not defined == Missing Reference: '0x23bc' is mentioned on line 592, but not defined == Missing Reference: 'RFCXXXX' is mentioned on line 4101, but not defined == Missing Reference: 'TBD1' is mentioned on line 4112, but not defined == Missing Reference: 'TBD2' is mentioned on line 4117, but not defined == Outdated reference: A later version (-11) exists of draft-ietf-tls-oob-pubkey-07 ** Obsolete normative reference: RFC 2616 (Obsoleted by RFC 7230, RFC 7231, RFC 7232, RFC 7233, RFC 7234, RFC 7235) ** Obsolete normative reference: RFC 3023 (Obsoleted by RFC 7303) ** Obsolete normative reference: RFC 4395 (Obsoleted by RFC 7595) ** Obsolete normative reference: RFC 5226 (Obsoleted by RFC 8126) ** Obsolete normative reference: RFC 5246 (Obsoleted by RFC 8446) ** Obsolete normative reference: RFC 5785 (Obsoleted by RFC 8615) ** Obsolete normative reference: RFC 5988 (Obsoleted by RFC 8288) ** Obsolete normative reference: RFC 6347 (Obsoleted by RFC 9147) == Outdated reference: A later version (-03) exists of draft-allman-tcpm-rto-consider-01 == Outdated reference: A later version (-27) exists of draft-bormann-coap-misc-23 == Outdated reference: A later version (-21) exists of draft-ietf-core-block-10 == Outdated reference: A later version (-16) exists of draft-ietf-core-observe-08 == Outdated reference: A later version (-08) exists of draft-mcgrew-tls-aes-ccm-ecc-06 -- Obsolete informational reference (is this intentional?): RFC 793 (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 2818 (Obsoleted by RFC 9110) -- Obsolete informational reference (is this intentional?): RFC 4492 (Obsoleted by RFC 8422) -- Obsolete informational reference (is this intentional?): RFC 4627 (Obsoleted by RFC 7158, RFC 7159) -- Obsolete informational reference (is this intentional?): RFC 5405 (Obsoleted by RFC 8085) Summary: 8 errors (**), 0 flaws (~~), 19 warnings (==), 7 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 CoRE Working Group Z. Shelby 3 Internet-Draft Sensinode 4 Intended status: Standards Track K. Hartke 5 Expires: September 13, 2013 C. Bormann 6 Universitaet Bremen TZI 7 March 12, 2013 9 Constrained Application Protocol (CoAP) 10 draft-ietf-core-coap-14 12 Abstract 14 The Constrained Application Protocol (CoAP) is a specialized web 15 transfer protocol for use with constrained nodes and constrained 16 (e.g., low-power, lossy) networks. The nodes often have 8-bit 17 microcontrollers with small amounts of ROM and RAM, while constrained 18 networks such as 6LoWPAN often have high packet error rates and a 19 typical throughput of 10s of kbit/s. The protocol is designed for 20 machine-to-machine (M2M) applications such as smart energy and 21 building automation. 23 CoAP provides a request/response interaction model between 24 application endpoints, supports built-in discovery of services and 25 resources, and includes key concepts of the Web such as URIs and 26 Internet media types. CoAP easily interfaces with HTTP for 27 integration with the Web while meeting specialized requirements such 28 as multicast support, very low overhead and simplicity for 29 constrained environments. 31 Status of this Memo 33 This Internet-Draft is submitted in full conformance with the 34 provisions of BCP 78 and BCP 79. 36 Internet-Drafts are working documents of the Internet Engineering 37 Task Force (IETF). Note that other groups may also distribute 38 working documents as Internet-Drafts. The list of current Internet- 39 Drafts is at http://datatracker.ietf.org/drafts/current/. 41 Internet-Drafts are draft documents valid for a maximum of six months 42 and may be updated, replaced, or obsoleted by other documents at any 43 time. It is inappropriate to use Internet-Drafts as reference 44 material or to cite them other than as "work in progress." 46 This Internet-Draft will expire on September 13, 2013. 48 Copyright Notice 49 Copyright (c) 2013 IETF Trust and the persons identified as the 50 document authors. All rights reserved. 52 This document is subject to BCP 78 and the IETF Trust's Legal 53 Provisions Relating to IETF Documents 54 (http://trustee.ietf.org/license-info) in effect on the date of 55 publication of this document. Please review these documents 56 carefully, as they describe your rights and restrictions with respect 57 to this document. Code Components extracted from this document must 58 include Simplified BSD License text as described in Section 4.e of 59 the Trust Legal Provisions and are provided without warranty as 60 described in the Simplified BSD License. 62 Table of Contents 64 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 5 65 1.1. Features . . . . . . . . . . . . . . . . . . . . . . . . 5 66 1.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 6 67 2. Constrained Application Protocol . . . . . . . . . . . . . . 9 68 2.1. Messaging Model . . . . . . . . . . . . . . . . . . . . . 10 69 2.2. Request/Response Model . . . . . . . . . . . . . . . . . 11 70 2.3. Intermediaries and Caching . . . . . . . . . . . . . . . 14 71 2.4. Resource Discovery . . . . . . . . . . . . . . . . . . . 14 72 3. Message Format . . . . . . . . . . . . . . . . . . . . . . . 15 73 3.1. Option Format . . . . . . . . . . . . . . . . . . . . . . 16 74 3.2. Option Value Formats . . . . . . . . . . . . . . . . . . 18 75 4. Message Transmission . . . . . . . . . . . . . . . . . . . . 19 76 4.1. Messages and Endpoints . . . . . . . . . . . . . . . . . 19 77 4.2. Messages Transmitted Reliably . . . . . . . . . . . . . . 20 78 4.3. Messages Transmitted Without Reliability . . . . . . . . 21 79 4.4. Message Correlation . . . . . . . . . . . . . . . . . . . 22 80 4.5. Message Deduplication . . . . . . . . . . . . . . . . . . 22 81 4.6. Message Size . . . . . . . . . . . . . . . . . . . . . . 23 82 4.7. Congestion Control . . . . . . . . . . . . . . . . . . . 24 83 4.8. Transmission Parameters . . . . . . . . . . . . . . . . . 25 84 4.8.1. Changing The Parameters . . . . . . . . . . . . . . . 25 85 4.8.2. Time Values derived from Transmission Parameters . . 26 86 5. Request/Response Semantics . . . . . . . . . . . . . . . . . 28 87 5.1. Requests . . . . . . . . . . . . . . . . . . . . . . . . 28 88 5.2. Responses . . . . . . . . . . . . . . . . . . . . . . . . 29 89 5.2.1. Piggy-backed . . . . . . . . . . . . . . . . . . . . 30 90 5.2.2. Separate . . . . . . . . . . . . . . . . . . . . . . 31 91 5.2.3. Non-confirmable . . . . . . . . . . . . . . . . . . . 32 92 5.3. Request/Response Matching . . . . . . . . . . . . . . . . 32 93 5.3.1. Token . . . . . . . . . . . . . . . . . . . . . . . . 32 94 5.3.2. Request/Response Matching Rules . . . . . . . . . . . 32 95 5.4. Options . . . . . . . . . . . . . . . . . . . . . . . . . 33 96 5.4.1. Critical/Elective . . . . . . . . . . . . . . . . . . 34 97 5.4.2. Proxy Unsafe/Safe and Cache-Key . . . . . . . . . . . 35 98 5.4.3. Length . . . . . . . . . . . . . . . . . . . . . . . 35 99 5.4.4. Default Values . . . . . . . . . . . . . . . . . . . 35 100 5.4.5. Repeatable Options . . . . . . . . . . . . . . . . . 36 101 5.4.6. Option Numbers . . . . . . . . . . . . . . . . . . . 36 102 5.5. Payloads and Representations . . . . . . . . . . . . . . 37 103 5.5.1. Representation . . . . . . . . . . . . . . . . . . . 37 104 5.5.2. Diagnostic Payload . . . . . . . . . . . . . . . . . 37 105 5.5.3. Selected Representation . . . . . . . . . . . . . . . 38 106 5.5.4. Content Negotiation . . . . . . . . . . . . . . . . . 38 107 5.6. Caching . . . . . . . . . . . . . . . . . . . . . . . . . 38 108 5.6.1. Freshness Model . . . . . . . . . . . . . . . . . . . 39 109 5.6.2. Validation Model . . . . . . . . . . . . . . . . . . 40 110 5.7. Proxying . . . . . . . . . . . . . . . . . . . . . . . . 40 111 5.7.1. Proxy Operation . . . . . . . . . . . . . . . . . . . 41 112 5.7.2. Forward-Proxies . . . . . . . . . . . . . . . . . . . 42 113 5.7.3. Reverse-Proxies . . . . . . . . . . . . . . . . . . . 43 114 5.8. Method Definitions . . . . . . . . . . . . . . . . . . . 43 115 5.8.1. GET . . . . . . . . . . . . . . . . . . . . . . . . . 43 116 5.8.2. POST . . . . . . . . . . . . . . . . . . . . . . . . 43 117 5.8.3. PUT . . . . . . . . . . . . . . . . . . . . . . . . . 44 118 5.8.4. DELETE . . . . . . . . . . . . . . . . . . . . . . . 44 119 5.9. Response Code Definitions . . . . . . . . . . . . . . . . 44 120 5.9.1. Success 2.xx . . . . . . . . . . . . . . . . . . . . 45 121 5.9.2. Client Error 4.xx . . . . . . . . . . . . . . . . . . 46 122 5.9.3. Server Error 5.xx . . . . . . . . . . . . . . . . . . 47 123 5.10. Option Definitions . . . . . . . . . . . . . . . . . . . 48 124 5.10.1. Uri-Host, Uri-Port, Uri-Path and Uri-Query . . . . . 49 125 5.10.2. Proxy-Uri and Proxy-Scheme . . . . . . . . . . . . . 50 126 5.10.3. Content-Format . . . . . . . . . . . . . . . . . . . 51 127 5.10.4. Accept . . . . . . . . . . . . . . . . . . . . . . . 51 128 5.10.5. Max-Age . . . . . . . . . . . . . . . . . . . . . . . 51 129 5.10.6. ETag . . . . . . . . . . . . . . . . . . . . . . . . 52 130 5.10.7. Location-Path and Location-Query . . . . . . . . . . 53 131 5.10.8. Conditional Request Options . . . . . . . . . . . . . 53 132 6. CoAP URIs . . . . . . . . . . . . . . . . . . . . . . . . . . 54 133 6.1. coap URI Scheme . . . . . . . . . . . . . . . . . . . . . 55 134 6.2. coaps URI Scheme . . . . . . . . . . . . . . . . . . . . 56 135 6.3. Normalization and Comparison Rules . . . . . . . . . . . 56 136 6.4. Decomposing URIs into Options . . . . . . . . . . . . . . 57 137 6.5. Composing URIs from Options . . . . . . . . . . . . . . . 58 138 7. Discovery . . . . . . . . . . . . . . . . . . . . . . . . . . 59 139 7.1. Service Discovery . . . . . . . . . . . . . . . . . . . . 59 140 7.2. Resource Discovery . . . . . . . . . . . . . . . . . . . 60 141 7.2.1. 'ct' Attribute . . . . . . . . . . . . . . . . . . . 60 142 8. Multicast CoAP . . . . . . . . . . . . . . . . . . . . . . . 60 143 8.1. Messaging Layer . . . . . . . . . . . . . . . . . . . . . 61 144 8.2. Request/Response Layer . . . . . . . . . . . . . . . . . 61 145 8.2.1. Caching . . . . . . . . . . . . . . . . . . . . . . . 62 146 8.2.2. Proxying . . . . . . . . . . . . . . . . . . . . . . 63 147 9. Securing CoAP . . . . . . . . . . . . . . . . . . . . . . . . 63 148 9.1. DTLS-secured CoAP . . . . . . . . . . . . . . . . . . . . 64 149 9.1.1. Messaging Layer . . . . . . . . . . . . . . . . . . . 65 150 9.1.2. Request/Response Layer . . . . . . . . . . . . . . . 66 151 9.1.3. Endpoint Identity . . . . . . . . . . . . . . . . . . 66 152 10. Cross-Protocol Proxying between CoAP and HTTP . . . . . . . . 68 153 10.1. CoAP-HTTP Proxying . . . . . . . . . . . . . . . . . . . 69 154 10.1.1. GET . . . . . . . . . . . . . . . . . . . . . . . . . 70 155 10.1.2. PUT . . . . . . . . . . . . . . . . . . . . . . . . . 70 156 10.1.3. DELETE . . . . . . . . . . . . . . . . . . . . . . . 71 157 10.1.4. POST . . . . . . . . . . . . . . . . . . . . . . . . 71 158 10.2. HTTP-CoAP Proxying . . . . . . . . . . . . . . . . . . . 71 159 10.2.1. OPTIONS and TRACE . . . . . . . . . . . . . . . . . . 72 160 10.2.2. GET . . . . . . . . . . . . . . . . . . . . . . . . . 72 161 10.2.3. HEAD . . . . . . . . . . . . . . . . . . . . . . . . 72 162 10.2.4. POST . . . . . . . . . . . . . . . . . . . . . . . . 73 163 10.2.5. PUT . . . . . . . . . . . . . . . . . . . . . . . . . 73 164 10.2.6. DELETE . . . . . . . . . . . . . . . . . . . . . . . 73 165 10.2.7. CONNECT . . . . . . . . . . . . . . . . . . . . . . . 73 166 11. Security Considerations . . . . . . . . . . . . . . . . . . . 74 167 11.1. Protocol Parsing, Processing URIs . . . . . . . . . . . . 74 168 11.2. Proxying and Caching . . . . . . . . . . . . . . . . . . 74 169 11.3. Risk of amplification . . . . . . . . . . . . . . . . . . 75 170 11.4. IP Address Spoofing Attacks . . . . . . . . . . . . . . . 76 171 11.5. Cross-Protocol Attacks . . . . . . . . . . . . . . . . . 77 172 12. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 79 173 12.1. CoAP Code Registry . . . . . . . . . . . . . . . . . . . 79 174 12.1.1. Method Codes . . . . . . . . . . . . . . . . . . . . 79 175 12.1.2. Response Codes . . . . . . . . . . . . . . . . . . . 80 176 12.2. Option Number Registry . . . . . . . . . . . . . . . . . 81 177 12.3. Content-Format Registry . . . . . . . . . . . . . . . . . 83 178 12.4. URI Scheme Registration . . . . . . . . . . . . . . . . . 84 179 12.5. Secure URI Scheme Registration . . . . . . . . . . . . . 85 180 12.6. Service Name and Port Number Registration . . . . . . . . 86 181 12.7. Secure Service Name and Port Number Registration . . . . 87 182 12.8. Multicast Address Registration . . . . . . . . . . . . . 88 183 13. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 88 184 14. References . . . . . . . . . . . . . . . . . . . . . . . . . 89 185 14.1. Normative References . . . . . . . . . . . . . . . . . . 89 186 14.2. Informative References . . . . . . . . . . . . . . . . . 91 187 Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 93 188 Appendix B. URI Examples . . . . . . . . . . . . . . . . . . . . 99 189 Appendix C. Changelog . . . . . . . . . . . . . . . . . . . . . 101 190 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 109 192 1. Introduction 194 The use of web services on the Internet has become ubiquitous in most 195 applications, and depends on the fundamental Representational State 196 Transfer [REST] architecture of the web. 198 The Constrained RESTful Environments (CoRE) work aims at realizing 199 the REST architecture in a suitable form for the most constrained 200 nodes (e.g. 8-bit microcontrollers with limited RAM and ROM) and 201 networks (e.g. 6LoWPAN, [RFC4944]). Constrained networks like 202 6LoWPAN support the expensive fragmentation of IPv6 packets into 203 small link-layer frames. One design goal of CoAP has been to keep 204 message overhead small, thus limiting the use of fragmentation. 206 One of the main goals of CoAP is to design a generic web protocol for 207 the special requirements of this constrained environment, especially 208 considering energy, building automation and other machine-to-machine 209 (M2M) applications. The goal of CoAP is not to blindly compress HTTP 210 [RFC2616], but rather to realize a subset of REST common with HTTP 211 but optimized for M2M applications. Although CoAP could be used for 212 compressing simple HTTP interfaces, it more importantly also offers 213 features for M2M such as built-in discovery, multicast support and 214 asynchronous message exchanges. 216 This document specifies the Constrained Application Protocol (CoAP), 217 which easily translates to HTTP for integration with the existing web 218 while meeting specialized requirements such as multicast support, 219 very low overhead and simplicity for constrained environments and M2M 220 applications. 222 1.1. Features 224 CoAP has the following main features: 226 o Constrained web protocol fulfilling M2M requirements. 228 o UDP [RFC0768] binding with optional reliability supporting unicast 229 and multicast requests. 231 o Asynchronous message exchanges. 233 o Low header overhead and parsing complexity. 235 o URI and Content-type support. 237 o Simple proxy and caching capabilities. 239 o A stateless HTTP mapping, allowing proxies to be built providing 240 access to CoAP resources via HTTP in a uniform way or for HTTP 241 simple interfaces to be realized alternatively over CoAP. 243 o Security binding to Datagram Transport Layer Security (DTLS) 244 [RFC6347]. 246 1.2. Terminology 248 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 249 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 250 "OPTIONAL" in this document are to be interpreted as described in 251 [RFC2119] when they appear in ALL CAPS. These words may also appear 252 in this document in lower case as plain English words, absent their 253 normative meanings. 255 This specification requires readers to be familiar with all the terms 256 and concepts that are discussed in [RFC2616]. In addition, this 257 specification defines the following terminology: 259 Endpoint 260 An entity participating in the CoAP protocol. Colloquially, an 261 endpoint lives on a "Node", although "Host" would be more 262 consistent with Internet standards usage, and is further 263 identified by transport layer multiplexing information that can 264 include a UDP port number and a security association 265 (Section 4.1). 267 Sender 268 The originating endpoint of a message. When the aspect of 269 identification of the specific sender is in focus, also "source 270 endpoint". 272 Recipient 273 The destination endpoint of a message. When the aspect of 274 identification of the specific recipient is in focus, also 275 "destination endpoint". 277 Client 278 The originating endpoint of a request; the destination endpoint of 279 a response. 281 Server 282 The destination endpoint of a request; the originating endpoint of 283 a response. 285 Origin Server 286 The server on which a given resource resides or is to be created. 288 Intermediary 289 A CoAP endpoint that acts both as a server and as a client towards 290 (possibly via further intermediaries) an origin server. A common 291 form of an intermediary is a proxy; several classes of such 292 proxies are discussed in this specification. 294 Proxy 295 An intermediary that mainly is concerned with forwarding requests 296 and relaying back responses, possibly performing caching, 297 namespace translation, or protocol translation in the process. As 298 opposed to intermediaries in the general sense, proxies generally 299 do not implement specific application semantics. Based on the 300 position in the overall structure of the request forwarding, there 301 are two common forms of proxy: forward-proxy and reverse-proxy. 302 In some cases, a single endpoint might act as an origin server, 303 forward-proxy, or reverse-proxy, switching behavior based on the 304 nature of each request. 306 Forward-Proxy 307 A "forward-proxy" is an endpoint selected by a client, usually via 308 local configuration rules, to perform requests on behalf of the 309 client, doing any necessary translations. Some translations are 310 minimal, such as for proxy requests for "coap" URIs, whereas other 311 requests might require translation to and from entirely different 312 application-layer protocols. 314 Reverse-Proxy 315 A "reverse-proxy" is an endpoint that stands in for one or more 316 other server(s) and satisfies requests on behalf of these, doing 317 any necessary translations. Unlike a forward-proxy, the client 318 may not be aware that it is communicating with a reverse-proxy; a 319 reverse-proxy receives requests as if it was the origin server for 320 the target resource. 322 Cross-Proxy 323 A cross-protocol proxy, or "cross-proxy" for short, is a proxy 324 that translates between different protocols, such as a CoAP-to- 325 HTTP proxy or an HTTP-to-CoAP proxy. While this specification 326 makes very specific demands of CoAP-to-CoAP proxies, there is more 327 variation possible in cross-proxies. 329 Confirmable Message 330 Some messages require an acknowledgement. These messages are 331 called "Confirmable". When no packets are lost, each Confirmable 332 message elicits exactly one return message of type Acknowledgement 333 or type Reset. 335 Non-confirmable Message 336 Some other messages do not require an acknowledgement. This is 337 particularly true for messages that are repeated regularly for 338 application requirements, such as repeated readings from a sensor. 340 Acknowledgement Message 341 An Acknowledgement message acknowledges that a specific 342 Confirmable Message arrived. It does not indicate success or 343 failure of any encapsulated request. 345 Reset Message 346 A Reset message indicates that a specific message (Confirmable or 347 Non-confirmable) was received, but some context is missing to 348 properly process it. This condition is usually caused when the 349 receiving node has rebooted and has forgotten some state that 350 would be required to interpret the message. Provoking a Reset 351 message (e.g., by sending an empty Confirmable message) is also 352 useful as an inexpensive check of the liveness of an endpoint 353 ("CoAP ping"). 355 Piggy-backed Response 356 A Piggy-backed Response is included right in a CoAP 357 Acknowledgement (ACK) message that is sent to acknowledge receipt 358 of the Request for this Response (Section 5.2.1). 360 Separate Response 361 When a Confirmable message carrying a Request is acknowledged with 362 an empty message (e.g., because the server doesn't have the answer 363 right away), a Separate Response is sent in a separate message 364 exchange (Section 5.2.2). 366 Critical Option 367 An option that would need to be understood by the endpoint 368 receiving the message in order to properly process the message 369 (Section 5.4.1). Note that the implementation of critical options 370 is, as the name "Option" implies, generally optional: unsupported 371 critical options lead to an error response or summary rejection of 372 the message. 374 Elective Option 375 An option that is intended to be ignored by an endpoint that does 376 not understand it. Processing the message even without 377 understanding the option is acceptable (Section 5.4.1). 379 Unsafe Option 380 An option that would need to be understood by a proxy receiving 381 the message in order to safely forward the message 382 (Section 5.4.2). 384 Safe Option 385 An option that is intended to be safe for forwarding by a proxy 386 that does not understand it. Forwarding the message even without 387 understanding the option is acceptable (Section 5.4.2). 389 Resource Discovery 390 The process where a CoAP client queries a server for its list of 391 hosted resources (i.e., links, Section 7). 393 Content-Format 394 The combination of an Internet media type, potentially with 395 specific parameters given, and a content-coding (which is often 396 the identity content-coding), identified by a numeric identifier 397 defined by the CoAP Content-Format registry. When the focus is 398 less on the numeric identifier than on the combination of these 399 characteristics of a resource representation, this is also called 400 "representation format". 402 In this specification, the term "byte" is used in its now customary 403 sense as a synonym for "octet". 405 All multi-byte integers in this protocol are interpreted in network 406 byte order. 408 Where arithmetic is used, this specification uses the notation 409 familiar from the programming language C, except that the operator 410 "**" stands for exponentiation. 412 2. Constrained Application Protocol 414 The interaction model of CoAP is similar to the client/server model 415 of HTTP. However, machine-to-machine interactions typically result 416 in a CoAP implementation acting in both client and server roles. A 417 CoAP request is equivalent to that of HTTP, and is sent by a client 418 to request an action (using a method code) on a resource (identified 419 by a URI) on a server. The server then sends a response with a 420 response code; this response may include a resource representation. 422 Unlike HTTP, CoAP deals with these interchanges asynchronously over a 423 datagram-oriented transport such as UDP. This is done logically 424 using a layer of messages that supports optional reliability (with 425 exponential back-off). CoAP defines four types of messages: 427 Confirmable, Non-confirmable, Acknowledgement, Reset; method codes 428 and response codes included in some of these messages make them carry 429 requests or responses. The basic exchanges of the four types of 430 messages are somewhat orthogonal to the request/response 431 interactions; requests can be carried in Confirmable and Non- 432 confirmable messages, and responses can be carried in these as well 433 as piggy-backed in Acknowledgement messages. 435 One could think of CoAP logically as using a two-layer approach, a 436 CoAP messaging layer used to deal with UDP and the asynchronous 437 nature of the interactions, and the request/response interactions 438 using Method and Response codes (see Figure 1). CoAP is however a 439 single protocol, with messaging and request/response just features of 440 the CoAP header. 442 +----------------------+ 443 | Application | 444 +----------------------+ 445 +----------------------+ \ 446 | Requests/Responses | | 447 |----------------------| | CoAP 448 | Messages | | 449 +----------------------+ / 450 +----------------------+ 451 | UDP | 452 +----------------------+ 454 Figure 1: Abstract layering of CoAP 456 2.1. Messaging Model 458 The CoAP messaging model is based on the exchange of messages over 459 UDP between endpoints. 461 CoAP uses a short fixed-length binary header (4 bytes) that may be 462 followed by compact binary options and a payload. This message 463 format is shared by requests and responses. The CoAP message format 464 is specified in Section 3. Each message contains a Message ID used 465 to detect duplicates and for optional reliability. 467 Reliability is provided by marking a message as Confirmable (CON). A 468 Confirmable message is retransmitted using a default timeout and 469 exponential back-off between retransmissions, until the recipient 470 sends an Acknowledgement message (ACK) with the same Message ID (for 471 example, 0x7d34) from the corresponding endpoint; see Figure 2. When 472 a recipient is not at all able to process a Confirmable message 473 (i.e., not even able to provide a suitable error response), it 474 replies with a Reset message (RST) instead of an Acknowledgement 475 (ACK). 477 Client Server 478 | | 479 | CON [0x7d34] | 480 +----------------->| 481 | | 482 | ACK [0x7d34] | 483 |<-----------------+ 484 | | 486 Figure 2: Reliable message transmission 488 A message that does not require reliable transmission, for example 489 each single measurement out of a stream of sensor data, can be sent 490 as a Non-confirmable message (NON). These are not acknowledged, but 491 still have a Message ID for duplicate detection; see Figure 3. When 492 a recipient is not able to process a Non-confirmable message, it may 493 reply with a Reset message (RST). 495 Client Server 496 | | 497 | NON [0x01a0] | 498 +----------------->| 499 | | 501 Figure 3: Unreliable message transmission 503 See Section 4 for details of CoAP messages. 505 As CoAP is based on UDP, it also supports the use of multicast IP 506 destination addresses, enabling multicast CoAP requests. Section 8 507 discusses the proper use of CoAP messages with multicast addresses 508 and precautions for avoiding response congestion. 510 Several security modes are defined for CoAP in Section 9 ranging from 511 no security to certificate-based security. This document specifies a 512 binding to DTLS for securing the protocol; the use of IPsec with CoAP 513 is discussed in [I-D.bormann-core-ipsec-for-coap]. 515 2.2. Request/Response Model 517 CoAP request and response semantics are carried in CoAP messages, 518 which include either a Method code or Response code, respectively. 519 Optional (or default) request and response information, such as the 520 URI and payload media type are carried as CoAP options. A Token is 521 used to match responses to requests independently from the underlying 522 messages (Section 5.3). 524 A request is carried in a Confirmable (CON) or Non-confirmable (NON) 525 message, and if immediately available, the response to a request 526 carried in a Confirmable message is carried in the resulting 527 Acknowledgement (ACK) message. This is called a piggy-backed 528 response, detailed in Section 5.2.1. Two examples for a basic GET 529 request with piggy-backed response are shown in Figure 4, one 530 successful, one resulting in a 4.04 (Not Found) response. 532 Client Server Client Server 533 | | | | 534 | CON [0xbc90] | | CON [0xbc91] | 535 | GET /temperature | | GET /temperature | 536 | (Token 0x71) | | (Token 0x72) | 537 +----------------->| +----------------->| 538 | | | | 539 | ACK [0xbc90] | | ACK [0xbc91] | 540 | 2.05 Content | | 4.04 Not Found | 541 | (Token 0x71) | | (Token 0x72) | 542 | "22.5 C" | | "Not found" | 543 |<-----------------+ |<-----------------+ 544 | | | | 546 Figure 4: Two GET requests with piggy-backed responses 548 If the server is not able to respond immediately to a request carried 549 in a Confirmable message, it simply responds with an empty 550 Acknowledgement message so that the client can stop retransmitting 551 the request. When the response is ready, the server sends it in a 552 new Confirmable message (which then in turn needs to be acknowledged 553 by the client). This is called a separate response, as illustrated 554 in Figure 5 and described in more detail in Section 5.2.2. 556 Client Server 557 | | 558 | CON [0x7a10] | 559 | GET /temperature | 560 | (Token 0x73) | 561 +----------------->| 562 | | 563 | ACK [0x7a10] | 564 |<-----------------+ 565 | | 566 ... Time Passes ... 567 | | 568 | CON [0x23bb] | 569 | 2.05 Content | 570 | (Token 0x73) | 571 | "22.5 C" | 572 |<-----------------+ 573 | | 574 | ACK [0x23bb] | 575 +----------------->| 576 | | 578 Figure 5: A GET request with a separate response 580 Likewise, if a request is sent in a Non-confirmable message, then the 581 response is usually sent using a new Non-confirmable message, 582 although the server may send a Confirmable message. This type of 583 exchange is illustrated in Figure 6. 585 Client Server 586 | | 587 | NON [0x7a11] | 588 | GET /temperature | 589 | (Token 0x74) | 590 +----------------->| 591 | | 592 | NON [0x23bc] | 593 | 2.05 Content | 594 | (Token 0x74) | 595 | "22.5 C" | 596 |<-----------------+ 597 | | 599 Figure 6: A NON request and response 601 CoAP makes use of GET, PUT, POST and DELETE methods in a similar 602 manner to HTTP, with the semantics specified in Section 5.8. (Note 603 that the detailed semantics of CoAP methods are "almost, but not 604 entirely unlike" those of HTTP methods: Intuition taken from HTTP 605 experience generally does apply well, but there are enough 606 differences that make it worthwhile to actually read the present 607 specification.) 609 URI support in a server is simplified as the client already parses 610 the URI and splits it into host, port, path and query components, 611 making use of default values for efficiency. Response codes 612 correspond to a small subset of HTTP response codes with a few CoAP 613 specific codes added, as defined in Section 5.9. 615 2.3. Intermediaries and Caching 617 The protocol supports the caching of responses in order to 618 efficiently fulfill requests. Simple caching is enabled using 619 freshness and validity information carried with CoAP responses. A 620 cache could be located in an endpoint or an intermediary. Caching 621 functionality is specified in Section 5.6. 623 Proxying is useful in constrained networks for several reasons, 624 including network traffic limiting, to improve performance, to access 625 resources of sleeping devices or for security reasons. The proxying 626 of requests on behalf of another CoAP endpoint is supported in the 627 protocol. When using a proxy, the URI of the resource to request is 628 included in the request, while the destination IP address is set to 629 the address of the proxy. See Section 5.7 for more information on 630 proxy functionality. 632 As CoAP was designed according to the REST architecture and thus 633 exhibits functionality similar to that of the HTTP protocol, it is 634 quite straightforward to map from CoAP to HTTP and from HTTP to CoAP. 635 Such a mapping may be used to realize an HTTP REST interface using 636 CoAP, or for converting between HTTP and CoAP. This conversion can 637 be carried out by a cross-protocol proxy ("cross-proxy"), which 638 converts the method or response code, media type, and options to the 639 corresponding HTTP feature. Section 10 provides more detail about 640 HTTP mapping. 642 2.4. Resource Discovery 644 Resource discovery is important for machine-to-machine interactions, 645 and is supported using the CoRE Link Format [RFC6690] as discussed in 646 Section 7. 648 3. Message Format 650 CoAP is based on the exchange of short messages which, by default, 651 are transported over UDP (i.e. each CoAP message occupies the data 652 section of one UDP datagram). CoAP may also be used over Datagram 653 Transport Layer Security (DTLS) (see Section 9.1). It could also be 654 used over other transports such as SMS, TCP or SCTP, the 655 specification of which is out of this document's scope. 657 CoAP messages are encoded in a simple binary format. The message 658 format starts with a fixed-size 4-byte header. This is followed by a 659 variable-length Token value which can be between 0 and 8 bytes long. 660 Following the Token value comes a sequence of zero or more CoAP 661 Options in Type-Length-Value (TLV) format, optionally followed by a 662 payload which takes up the rest of the datagram. 664 0 1 2 3 665 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 666 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 667 |Ver| T | TKL | Code | Message ID | 668 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 669 | Token (if any, TKL bytes) ... 670 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 671 | Options (if any) ... 672 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 673 |1 1 1 1 1 1 1 1| Payload (if any) ... 674 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 676 Figure 7: Message Format 678 The fields in the header are defined as follows: 680 Version (Ver): 2-bit unsigned integer. Indicates the CoAP version 681 number. Implementations of this specification MUST set this field 682 to 1. Other values are reserved for future versions. 684 Type (T): 2-bit unsigned integer. Indicates if this message is of 685 type Confirmable (0), Non-confirmable (1), Acknowledgement (2) or 686 Reset (3). The semantics of these message types are defined in 687 Section 4. 689 Token Length (TKL): 4-bit unsigned integer. Indicates the length of 690 the variable-length Token field (0-8 bytes). Lengths 9-15 are 691 reserved, MUST NOT be sent, and MUST be processed as a message 692 format error. 694 Code: 8-bit unsigned integer. Indicates if the message carries a 695 request (1-31) or a response (64-191), or is empty (0). (All 696 other code values are reserved.) In case of a request, the Code 697 field indicates the Request Method; in case of a response a 698 Response Code. Possible values are maintained in the CoAP Code 699 Registry (Section 12.1). The semantics of requests and responses 700 are defined in Section 5. 702 Message ID: 16-bit unsigned integer in network byte order. Used for 703 the detection of message duplication, and to match messages of 704 type Acknowledgement/Reset to messages of type Confirmable/ 705 Non-confirmable. The rules for generating a Message ID and 706 matching messages are defined in Section 4. 708 The header is followed by the Token value, which may be 0 to 8 bytes, 709 as given by the Token Length field. The Token value is used to 710 correlate requests and responses. The rules for generating a Token 711 and correlating requests and responses are defined in Section 5.3.1. 713 Header and Token are followed by zero or more Options (Section 3.1). 714 An Option can be followed by the end of the message, by another 715 Option, or by the Payload Marker and the payload. 717 Following the header, token, and options, if any, comes the optional 718 payload. If present and of non-zero length, it is prefixed by a 719 fixed, one-byte Payload Marker (0xFF) which indicates the end of 720 options and the start of the payload. The payload data extends from 721 after the marker to the end of the UDP datagram, i.e., the Payload 722 Length is calculated from the datagram size. The absence of the 723 Payload Marker denotes a zero-length payload. The presence of a 724 marker followed by a zero-length payload MUST be processed as a 725 message format error. 727 3.1. Option Format 729 CoAP defines a number of options which can be included in a message. 730 Each option instance in a message specifies the Option Number of the 731 defined CoAP option, the length of the Option Value and the Option 732 Value itself. 734 Instead of specifying the Option Number directly, the instances MUST 735 appear in order of their Option Numbers and a delta encoding is used 736 between them: The Option Number for each instance is calculated as 737 the sum of its delta and the Option Number of the preceding instance 738 in the message. For the first instance in a message, a preceding 739 option instance with Option Number zero is assumed. Multiple 740 instances of the same option can be included by using a delta of 741 zero. 743 Option Numbers are maintained in the CoAP Option Number Registry 744 (Section 12.2). See Section 5.4 for the semantics of the options 745 defined in this document. 747 0 1 2 3 4 5 6 7 748 +---------------+---------------+ 749 | | | 750 | Option Delta | Option Length | 1 byte 751 | | | 752 +---------------+---------------+ 753 \ \ 754 / Option Delta / 0-2 bytes 755 \ (extended) \ 756 +-------------------------------+ 757 \ \ 758 / Option Length / 0-2 bytes 759 \ (extended) \ 760 +-------------------------------+ 761 \ \ 762 / / 763 \ \ 764 / Option Value / 0 or more bytes 765 \ \ 766 / / 767 \ \ 768 +-------------------------------+ 770 Figure 8: Option Format 772 The fields in an option are defined as follows: 774 Option Delta: 4-bit unsigned integer. A value between 0 and 12 775 indicates the Option Delta. Three values are reserved for special 776 constructs: 778 13: An 8-bit unsigned integer follows the initial byte and 779 indicates the Option Delta minus 13. 781 14: A 16-bit unsigned integer in network byte order follows the 782 initial byte and indicates the Option Delta minus 269. 784 15: Reserved for the Payload Marker. If the field is set to this 785 value but the entire byte is not the payload marker, this MUST 786 be processed as a message format error. 788 The resulting Option Delta is used as the difference between the 789 Option Number of this option and that of the previous option (or 790 zero for the first option). In other words, the Option Number is 791 calculated by simply summing the Option Delta values of this and 792 all previous options before it. 794 Option Length: 4-bit unsigned integer. A value between 0 and 12 795 indicates the length of the Option Value, in bytes. Three values 796 are reserved for special constructs: 798 13: An 8-bit unsigned integer precedes the Option Value and 799 indicates the Option Length minus 13. 801 14: A 16-bit unsigned integer in network byte order precedes the 802 Option Value and indicates the Option Length minus 269. 804 15: Reserved for future use. If the field is set to this value, 805 it MUST be processed as a message format error. 807 Value: A sequence of exactly Option Length bytes. The length and 808 format of the Option Value depend on the respective option, which 809 MAY define variable length values. See Section 3.2 for the 810 formats used in this document; options defined in other documents 811 MAY make use of other option value formats. 813 3.2. Option Value Formats 815 The options defined in this document make use of the following option 816 value formats. 818 empty: A zero-length sequence of bytes. 820 opaque: An opaque sequence of bytes. 822 uint: A non-negative integer which is represented in network byte 823 order using the number of bytes given by the Option Length 824 field. 826 An option definition may specify a range of permissible 827 numbers of bytes; if it has a choice, a sender SHOULD 828 represent the integer with as few bytes as possible, i.e., 829 without leading zero bytes. For example, the number 0 is 830 represented with an empty option value (a zero-length 831 sequence of bytes), and the number 1 by a single byte with 832 the numerical value of 1 (bit combination 00000001 in most 833 significant bit first notation). A recipient MUST be 834 prepared to process values with leading zero bytes. 836 Implementation Note: The exceptional behavior permitted 837 for the sender is intended for highly 838 constrained, templated implementations (e.g., 839 hardware implementations) that use fixed size 840 options in the templates. 842 string: A Unicode string which is encoded using UTF-8 [RFC3629] in 843 Net-Unicode form [RFC5198]. 845 Note that here and in all other places where UTF-8 encoding 846 is used in the CoAP protocol, the intention is that the 847 encoded strings can be directly used and compared as opaque 848 byte strings by CoAP protocol implementations. There is no 849 expectation and no need to perform normalization within a 850 CoAP implementation (except where Unicode strings that are 851 not known to be normalized are imported from sources 852 outside the CoAP protocol). Note also that ASCII strings 853 (that do not make use of special control characters) are 854 always valid UTF-8 Net-Unicode strings. 856 4. Message Transmission 858 CoAP messages are exchanged asynchronously between CoAP endpoints. 859 They are used to transport CoAP requests and responses, the semantics 860 of which are defined in Section 5. 862 As CoAP is bound to non-reliable transports such as UDP, CoAP 863 messages may arrive out of order, appear duplicated, or go missing 864 without notice. For this reason, CoAP implements a lightweight 865 reliability mechanism, without trying to re-create the full feature 866 set of a transport like TCP. It has the following features: 868 o Simple stop-and-wait retransmission reliability with exponential 869 back-off for Confirmable messages. 871 o Duplicate detection for both Confirmable and Non-confirmable 872 messages. 874 4.1. Messages and Endpoints 876 A CoAP endpoint is the source or destination of a CoAP message. The 877 specific definition of an endpoint depends on the transport being 878 used for CoAP. For the transports defined in this specification, the 879 endpoint is identified depending on the security mode used (see 880 Section 9): With no security, the endpoint is solely identified by an 881 IP address and a UDP port number. With other security modes, the 882 endpoint is identified as defined by the security mode. 884 There are different types of messages. The type of a message is 885 specified by the Type field of the CoAP Header. 887 Separate from the message type, a message may carry a request, a 888 response, or be empty. This is signaled by the Request/Response Code 889 field in the CoAP Header and is relevant to the request/response 890 model. Possible values for the field are maintained in the CoAP Code 891 Registry (Section 12.1). 893 An empty message has the Code field set to 0. The Token Length field 894 MUST be set to 0 and no bytes MUST be present after the Message ID 895 field. If there are any bytes, they MUST be processed as a message 896 format error. 898 4.2. Messages Transmitted Reliably 900 The reliable transmission of a message is initiated by marking the 901 message as Confirmable in the CoAP header. A Confirmable message 902 always carries either a request or response and MUST NOT be empty, 903 unless it is used only to elicit a Reset message. A recipient MUST 904 acknowledge such a message with an Acknowledgement message or, if it 905 lacks context to process the message properly (including the case 906 where the message is empty or has a message format error), MUST 907 reject it; rejecting a Confirmable message is effected by sending a 908 matching Reset message and otherwise ignoring it. The 909 Acknowledgement message MUST echo the Message ID of the Confirmable 910 message, and MUST carry a response or be empty (see Section 5.2.1 and 911 Section 5.2.2). The Reset message MUST echo the Message ID of the 912 Confirmable message, and MUST be empty. Rejecting an Acknowledgement 913 or Reset message is effected by silently ignoring it. More 914 generally, Acknowledgement and Reset messages MUST NOT elicit any 915 Acknowledgement or Reset message from their recipient. 917 The sender retransmits the Confirmable message at exponentially 918 increasing intervals, until it receives an acknowledgement (or Reset 919 message), or runs out of attempts. 921 Retransmission is controlled by two things that a CoAP endpoint MUST 922 keep track of for each Confirmable message it sends while waiting for 923 an acknowledgement (or reset): a timeout and a retransmission 924 counter. For a new Confirmable message, the initial timeout is set 925 to a random number between ACK_TIMEOUT and (ACK_TIMEOUT * 926 ACK_RANDOM_FACTOR) (see Section 4.8), and the retransmission counter 927 is set to 0. When the timeout is triggered and the retransmission 928 counter is less than MAX_RETRANSMIT, the message is retransmitted, 929 the retransmission counter is incremented, and the timeout is 930 doubled. If the retransmission counter reaches MAX_RETRANSMIT on a 931 timeout, or if the endpoint receives a Reset message, then the 932 attempt to transmit the message is canceled and the application 933 process informed of failure. On the other hand, if the endpoint 934 receives an acknowledgement in time, transmission is considered 935 successful. 937 A CoAP endpoint that sent a Confirmable message MAY give up in 938 attempting to obtain an ACK even before the MAX_RETRANSMIT counter 939 value is reached: E.g., the application has canceled the request as 940 it no longer needs a response, or there is some other indication that 941 the CON message did arrive. In particular, a CoAP request message 942 may have elicited a separate response, in which case it is clear to 943 the requester that only the ACK was lost and a retransmission of the 944 request would serve no purpose. However, a responder MUST NOT in 945 turn rely on this cross-layer behavior from a requester, i.e. it 946 SHOULD retain the state to create the ACK for the request, if needed, 947 even if a Confirmable response was already acknowledged by the 948 requester. 950 4.3. Messages Transmitted Without Reliability 952 Some messages do not require an acknowledgement. This is 953 particularly true for messages that are repeated regularly for 954 application requirements, such as repeated readings from a sensor 955 where eventual success is sufficient. 957 As a more lightweight alternative, a message can be transmitted less 958 reliably by marking the message as Non-confirmable. A Non- 959 confirmable message always carries either a request or response and 960 MUST NOT be empty. A Non-confirmable message MUST NOT be 961 acknowledged by the recipient. If a recipient lacks context to 962 process the message properly (including the case where the message is 963 empty or has a message format error), it MUST reject the message; 964 rejecting a Non-confirmable message MAY involve sending a matching 965 Reset message, and apart from the Reset message the rejected message 966 MUST be silently ignored. 968 At the CoAP level, there is no way for the sender to detect if a Non- 969 confirmable message was received or not. A sender MAY choose to 970 transmit multiple copies of a Non-confirmable message within 971 MAX_TRANSMIT_SPAN, or the network may duplicate the message in 972 transit. To enable the receiver to act only once on the message, 973 Non-confirmable messages specify a Message ID as well. (This Message 974 ID is drawn from the same number space as the Message IDs for 975 Confirmable messages.) 977 4.4. Message Correlation 979 An Acknowledgement or Reset message is related to a Confirmable 980 message or Non-confirmable message by means of a Message ID along 981 with additional address information of the corresponding endpoint. 982 The Message ID is a 16-bit unsigned integer that is generated by the 983 sender of a Confirmable or Non-confirmable message and included in 984 the CoAP header. The Message ID MUST be echoed in the 985 Acknowledgement or Reset message by the recipient. 987 The same Message ID MUST NOT be re-used (in communicating with the 988 same endpoint) within the EXCHANGE_LIFETIME (Section 4.8.2). 990 Implementation Note: Several implementation strategies can be 991 employed for generating Message IDs. In the simplest case a CoAP 992 endpoint generates Message IDs by keeping a single Message ID 993 variable, which is changed each time a new Confirmable or Non- 994 confirmable message is sent regardless of the destination address 995 or port. Endpoints dealing with large numbers of transactions 996 could keep multiple Message ID variables, for example per prefix 997 or destination address. The initial variable value should be 998 randomized. 1000 For an Acknowledgement or Reset message to match a Confirmable or 1001 Non-confirmable message, the Message ID and source endpoint of the 1002 Acknowledgement or Reset message MUST match the Message ID and 1003 destination endpoint of the Confirmable or Non-confirmable message. 1005 4.5. Message Deduplication 1007 A recipient MUST be prepared to receive the same Confirmable message 1008 (as indicated by the Message ID and source endpoint) multiple times 1009 within the EXCHANGE_LIFETIME (Section 4.8.2), for example, when its 1010 Acknowledgement went missing or didn't reach the original sender 1011 before the first timeout. The recipient SHOULD acknowledge each 1012 duplicate copy of a Confirmable message using the same 1013 Acknowledgement or Reset message, but SHOULD process any request or 1014 response in the message only once. This rule MAY be relaxed in case 1015 the Confirmable message transports a request that is idempotent (see 1016 Section 5.1) or can be handled in an idempotent fashion. Examples 1017 for relaxed message deduplication: 1019 o A server MAY relax the requirement to answer all retransmissions 1020 of an idempotent request with the same response (Section 4.2), so 1021 that it does not have to maintain state for Message IDs. For 1022 example, an implementation might want to process duplicate 1023 transmissions of a GET, PUT or DELETE request as separate requests 1024 if the effort incurred by duplicate processing is less expensive 1025 than keeping track of previous responses would be. 1027 o A constrained server MAY even want to relax this requirement for 1028 certain non-idempotent requests if the application semantics make 1029 this trade-off favorable. For example, if the result of a POST 1030 request is just the creation of some short-lived state at the 1031 server, it may be less expensive to incur this effort multiple 1032 times for a request than keeping track of whether a previous 1033 transmission of the same request already was processed. 1035 A recipient MUST be prepared to receive the same Non-confirmable 1036 message (as indicated by the Message ID and source endpoint) multiple 1037 times within NON_LIFETIME (Section 4.8.2). As a general rule that 1038 MAY be relaxed based on the specific semantics of a message, the 1039 recipient SHOULD silently ignore any duplicated Non-confirmable 1040 message, and SHOULD process any request or response in the message 1041 only once. 1043 4.6. Message Size 1045 While specific link layers make it beneficial to keep CoAP messages 1046 small enough to fit into their link layer packets (see Section 1), 1047 this is a matter of implementation quality. The CoAP specification 1048 itself provides only an upper bound to the message size. Messages 1049 larger than an IP fragment result in undesired packet fragmentation. 1050 A CoAP message, appropriately encapsulated, SHOULD fit within a 1051 single IP packet (i.e., avoid IP fragmentation) and (by fitting into 1052 one UDP payload) obviously MUST fit within a single IP datagram. If 1053 the Path MTU is not known for a destination, an IP MTU of 1280 bytes 1054 SHOULD be assumed; if nothing is known about the size of the headers, 1055 good upper bounds are 1152 bytes for the message size and 1024 bytes 1056 for the payload size. 1058 Implementation Note: CoAP's choice of message size parameters works 1059 well with IPv6 and with most of today's IPv4 paths. (However, 1060 with IPv4, it is harder to absolutely ensure that there is no IP 1061 fragmentation. If IPv4 support on unusual networks is a 1062 consideration, implementations may want to limit themselves to 1063 more conservative IPv4 datagram sizes such as 576 bytes; worse, 1064 the absolute minimum value of the IP MTU for IPv4 is as low as 68 1065 bytes, which would leave only 40 bytes minus security overhead for 1066 a UDP payload. Implementations extremely focused on this problem 1067 set might also set the IPv4 DF bit and perform some form of path 1068 MTU discovery; this should generally be unnecessary in most 1069 realistic use cases for CoAP, however.) A more important kind of 1070 fragmentation in many constrained networks is that on the 1071 adaptation layer (e.g., 6LoWPAN L2 packets are limited to 127 1072 bytes including various overheads); this may motivate 1073 implementations to be frugal in their packet sizes and to move to 1074 block-wise transfers [I-D.ietf-core-block] when approaching three- 1075 digit message sizes. 1077 Message sizes are also of considerable importance to 1078 implementations on constrained nodes. Many implementations will 1079 need to allocate a buffer for incoming messages. If an 1080 implementation is too constrained to allow for allocating the 1081 above-mentioned upper bound, it could apply the following 1082 implementation strategy: Implementations receiving a datagram into 1083 a buffer that is too small are usually able to determine if the 1084 trailing portion of a datagram was discarded and to retrieve the 1085 initial portion. So, if not all of the payload, at least the CoAP 1086 header and options are likely to fit within the buffer. A server 1087 can thus fully interpret a request and return a 4.13 (Request 1088 Entity Too Large) response code if the payload was truncated. A 1089 client sending an idempotent request and receiving a response 1090 larger than would fit in the buffer can repeat the request with a 1091 suitable value for the Block Option [I-D.ietf-core-block]. 1093 4.7. Congestion Control 1095 Basic congestion control for CoAP is provided by the exponential 1096 back-off mechanism in Section 4.2. 1098 In order not to cause congestion, Clients (including proxies) MUST 1099 strictly limit the number of simultaneous outstanding interactions 1100 that they maintain to a given server (including proxies) to NSTART. 1101 An outstanding interaction is either a CON for which an ACK has not 1102 yet been received but is still expected (message layer) or a request 1103 for which neither a response nor an Acknowledgment message has yet 1104 been received but is still expected (which may both occur at the same 1105 time, counting as one outstanding interaction). The default value of 1106 NSTART for this specification is 1. 1108 Further congestion control optimizations and considerations are 1109 expected in the future, which may for example provide automatic 1110 initialization of the CoAP transmission parameters defined in 1111 Section 4.8, and thus may allow a value for NSTART greater than one. 1113 A client stops expecting a response to a Confirmable request for 1114 which no acknowledgment message was received, after 1115 EXCHANGE_LIFETIME. The specific algorithm by which a client stops to 1116 "expect" a response to a Confirmable request that was acknowledged, 1117 or to a Non-confirmable request, is not defined. Unless this is 1118 modified by additional congestion control optimizations, it MUST be 1119 chosen in such a way that an endpoint does not exceed an average data 1120 rate of PROBING_RATE in sending to another endpoint that does not 1121 respond. 1123 Note: CoAP places the onus of congestion control mostly on the 1124 clients. However, clients may malfunction or actually be 1125 attackers, e.g. to perform amplification attacks (Section 11.3). 1126 To limit the damage (to the network and to its own energy 1127 resources), a server SHOULD implement some rate limiting for its 1128 response transmission based on reasonable assumptions about 1129 application requirements. This is most helpful if the rate limit 1130 can be made effective for the misbehaving endpoints, only. 1132 4.8. Transmission Parameters 1134 Message transmission is controlled by the following parameters: 1136 +-------------------+---------------+ 1137 | name | default value | 1138 +-------------------+---------------+ 1139 | ACK_TIMEOUT | 2 seconds | 1140 | ACK_RANDOM_FACTOR | 1.5 | 1141 | MAX_RETRANSMIT | 4 | 1142 | NSTART | 1 | 1143 | DEFAULT_LEISURE | 5 seconds | 1144 | PROBING_RATE | 1 Byte/second | 1145 +-------------------+---------------+ 1147 Table 1: CoAP Protocol Parameters 1149 4.8.1. Changing The Parameters 1151 The values for ACK_TIMEOUT, ACK_RANDOM_FACTOR, MAX_RETRANSMIT, 1152 NSTART, DEFAULT_LEISURE, and PROBING_RATE may be configured to values 1153 specific to the application environment (including dynamically 1154 adjusted values), however the configuration method is out of scope of 1155 this document. It is recommended that an application environment use 1156 consistent values for these parameters. 1158 The transmission parameters have been chosen to achieve a behavior in 1159 the presence of congestion that is safe in the Internet. If a 1160 configuration desires to use different values, the onus is on the 1161 configuration to ensure these congestion control properties are not 1162 violated. In particular, a decrease of ACK_TIMEOUT below 1 second 1163 would violate the guidelines of [RFC5405]. 1164 ([I-D.allman-tcpm-rto-consider] provides some additional background.) 1165 CoAP was designed to enable implementations that do not maintain 1166 round-trip-time (RTT) measurements. However, where it is desired to 1167 decrease the ACK_TIMEOUT significantly or increase NSTART, this can 1168 only be done safely when maintaining such measurements. 1170 Configurations MUST NOT decrease ACK_TIMEOUT or increase NSTART 1171 without using mechanisms that ensure congestion control safety, 1172 either defined in the configuration or in future standards documents. 1174 ACK_RANDOM_FACTOR MUST NOT be decreased below 1.0, and it SHOULD have 1175 a value that is sufficiently different from 1.0 to provide some 1176 protection from synchronization effects. 1178 MAX_RETRANSMIT can be freely adjusted, but a too small value will 1179 reduce the probability that a Confirmable message is actually 1180 received, while a larger value than given here will require further 1181 adjustments in the time values (see Section 4.8.2). 1183 If the choice of transmission parameters leads to an increase of 1184 derived time values (see Section 4.8.2), the configuration mechanism 1185 MUST ensure the adjusted value is also available to all the endpoints 1186 that these adjusted values are to be used to communicate with. 1188 4.8.2. Time Values derived from Transmission Parameters 1190 The combination of ACK_TIMEOUT, ACK_RANDOM_FACTOR and MAX_RETRANSMIT 1191 influences the timing of retransmissions, which in turn influences 1192 how long certain information items need to be kept by an 1193 implementation. To be able to unambiguously reference these derived 1194 time values, we give them names as follows: 1196 o MAX_TRANSMIT_SPAN is the maximum time from the first transmission 1197 of a Confirmable message to its last retransmission. For the 1198 default transmission parameters, the value is (2+4+8+16)*1.5 = 45 1199 seconds, or more generally: 1201 ACK_TIMEOUT * (2 ** MAX_RETRANSMIT - 1) * ACK_RANDOM_FACTOR 1203 o MAX_TRANSMIT_WAIT is the maximum time from the first transmission 1204 of a Confirmable message to the time when the sender gives up on 1205 receiving an acknowledgement or reset. For the default 1206 transmission parameters, the value is (2+4+8+16+32)*1.5 = 93 1207 seconds, or more generally: 1209 ACK_TIMEOUT * (2 ** (MAX_RETRANSMIT + 1) - 1) * 1210 ACK_RANDOM_FACTOR 1212 In addition, some assumptions need to be made on the characteristics 1213 of the network and the nodes. 1215 o MAX_LATENCY is the maximum time a datagram is expected to take 1216 from the start of its transmission to the completion of its 1217 reception. This constant is related to the MSL (Maximum Segment 1218 Lifetime) of [RFC0793], which is "arbitrarily defined to be 2 1219 minutes" ([RFC0793] glossary, page 81). Note that this is not 1220 necessarily smaller than MAX_TRANSMIT_WAIT, as MAX_LATENCY is not 1221 intended to describe a situation when the protocol works well, but 1222 the worst case situation against which the protocol has to guard. 1223 We, also arbitrarily, define MAX_LATENCY to be 100 seconds. Apart 1224 from being reasonably realistic for the bulk of configurations as 1225 well as close to the historic choice for TCP, this value also 1226 allows Message ID lifetime timers to be represented in 8 bits 1227 (when measured in seconds). In these calculations, there is no 1228 assumption that the direction of the transmission is irrelevant 1229 (i.e. that the network is symmetric), just that the same value can 1230 reasonably be used as a maximum value for both directions. If 1231 that is not the case, the following calculations become only 1232 slightly more complex. 1234 o PROCESSING_DELAY is the time a node takes to turn around a 1235 Confirmable message into an acknowledgement. We assume the node 1236 will attempt to send an ACK before having the sender time out, so 1237 as a conservative assumption we set it equal to ACK_TIMEOUT. 1239 o MAX_RTT is the maximum round-trip time, or: 1241 2 * MAX_LATENCY + PROCESSING_DELAY 1243 From these values, we can derive the following values relevant to the 1244 protocol operation: 1246 o EXCHANGE_LIFETIME is the time from starting to send a Confirmable 1247 message to the time when an acknowledgement is no longer expected, 1248 i.e. message layer information about the message exchange can be 1249 purged. EXCHANGE_LIFETIME includes a MAX_TRANSMIT_SPAN, a 1250 MAX_LATENCY forward, PROCESSING_DELAY, and a MAX_LATENCY for the 1251 way back. Note that there is no need to consider 1252 MAX_TRANSMIT_WAIT if the configuration is chosen such that the 1253 last waiting period (ACK_TIMEOUT * (2 ** MAX_RETRANSMIT) or the 1254 difference between MAX_TRANSMIT_SPAN and MAX_TRANSMIT_WAIT) is 1255 less than MAX_LATENCY -- which is a likely choice, as MAX_LATENCY 1256 is a worst case value unlikely to be met in the real world. In 1257 this case, EXCHANGE_LIFETIME simplifies to: 1259 MAX_TRANSMIT_SPAN + (2 * MAX_LATENCY) + PROCESSING_DELAY 1261 or 247 seconds with the default transmission parameters. 1263 o NON_LIFETIME is the time from sending a Non-confirmable message to 1264 the time its Message ID can be safely reused. If multiple 1265 transmission of a NON message is not used, its value is 1266 MAX_LATENCY, or 100 seconds. However, a CoAP sender might send a 1267 NON message multiple times, in particular for multicast 1268 applications. While the period of re-use is not bounded by the 1269 specification, an expectation of reliable detection of duplication 1270 at the receiver is in the timescales of MAX_TRANSMIT_SPAN. 1271 Therefore, for this purpose, it is safer to use the value: 1273 MAX_TRANSMIT_SPAN + MAX_LATENCY 1275 or 145 seconds with the default transmission parameters; however, 1276 an implementation that just wants to use a single timeout value 1277 for retiring Messagen IDs can safely use the larger value for 1278 EXCHANGE_LIFETIME. 1280 Table 2 summarizes the derived parameters introduced in this 1281 subsection with their default values. 1283 +-------------------+---------------+ 1284 | name | default value | 1285 +-------------------+---------------+ 1286 | MAX_TRANSMIT_SPAN | 45 s | 1287 | MAX_TRANSMIT_WAIT | 93 s | 1288 | MAX_LATENCY | 100 s | 1289 | PROCESSING_DELAY | 2 s | 1290 | MAX_RTT | 202 s | 1291 | EXCHANGE_LIFETIME | 247 s | 1292 | NON_LIFETIME | 145 s | 1293 +-------------------+---------------+ 1295 Table 2: Derived Protocol Parameters 1297 5. Request/Response Semantics 1299 CoAP operates under a similar request/response model as HTTP: a CoAP 1300 endpoint in the role of a "client" sends one or more CoAP requests to 1301 a "server", which services the requests by sending CoAP responses. 1302 Unlike HTTP, requests and responses are not sent over a previously 1303 established connection, but exchanged asynchronously over CoAP 1304 messages. 1306 5.1. Requests 1308 A CoAP request consists of the method to be applied to the resource, 1309 the identifier of the resource, a payload and Internet media type (if 1310 any), and optional meta-data about the request. 1312 CoAP supports the basic methods of GET, POST, PUT, DELETE, which are 1313 easily mapped to HTTP. They have the same properties of safe (only 1314 retrieval) and idempotent (you can invoke it multiple times with the 1315 same effects) as HTTP (see Section 9.1 of [RFC2616]). The GET method 1316 is safe, therefore it MUST NOT take any other action on a resource 1317 other than retrieval. The GET, PUT and DELETE methods MUST be 1318 performed in such a way that they are idempotent. POST is not 1319 idempotent, because its effect is determined by the origin server and 1320 dependent on the target resource; it usually results in a new 1321 resource being created or the target resource being updated. 1323 A request is initiated by setting the Code field in the CoAP header 1324 of a Confirmable or a Non-confirmable message to a Method Code and 1325 including request information. 1327 The methods used in requests are described in detail in Section 5.8. 1329 5.2. Responses 1331 After receiving and interpreting a request, a server responds with a 1332 CoAP response, which is matched to the request by means of a client- 1333 generated token (Section 5.3, note that this is different from the 1334 Message ID that matches a Confirmable message to its 1335 Acknowledgement). 1337 A response is identified by the Code field in the CoAP header being 1338 set to a Response Code. Similar to the HTTP Status Code, the CoAP 1339 Response Code indicates the result of the attempt to understand and 1340 satisfy the request. These codes are fully defined in Section 5.9. 1341 The Response Code numbers to be set in the Code field of the CoAP 1342 header are maintained in the CoAP Response Code Registry 1343 (Section 12.1.2). 1345 0 1346 0 1 2 3 4 5 6 7 1347 +-+-+-+-+-+-+-+-+ 1348 |class| detail | 1349 +-+-+-+-+-+-+-+-+ 1351 Figure 9: Structure of a Response Code 1353 The upper three bits of the 8-bit Response Code number define the 1354 class of response. The lower five bits do not have any 1355 categorization role; they give additional detail to the overall class 1356 (Figure 9). 1358 As a human readable notation for specifications and protocol 1359 diagnostics, the response code is documented in the format "c.dd", 1360 where "c" is the class in decimal, and "dd" is the detail as a two- 1361 digit decimal. For example, "Forbidden" is written as 4.03 -- 1362 indicating a value of 4*32+3, hexadecimal 0x83 or decimal 131. 1364 There are 3 classes: 1366 2 - Success: The request was successfully received, understood, and 1367 accepted. 1369 4 - Client Error: The request contains bad syntax or cannot be 1370 fulfilled. 1372 5 - Server Error: The server failed to fulfill an apparently valid 1373 request. 1375 The response codes are designed to be extensible: Response Codes in 1376 the Client Error and Server Error class that are unrecognized by an 1377 endpoint MUST be treated as being equivalent to the generic Response 1378 Code of that class (4.00 and 5.00, respectively). However, there is 1379 no generic Response Code indicating success, so a Response Code in 1380 the Success class that is unrecognized by an endpoint can only be 1381 used to determine that the request was successful without any further 1382 details. 1384 The possible response codes are described in detail in Section 5.9. 1386 Responses can be sent in multiple ways, which are defined in the 1387 following subsections. 1389 5.2.1. Piggy-backed 1391 In the most basic case, the response is carried directly in the 1392 Acknowledgement message that acknowledges the request (which requires 1393 that the request was carried in a Confirmable message). This is 1394 called a "Piggy-backed" Response. 1396 The response is returned in the Acknowledgement message independent 1397 of whether the response indicates success or failure. In effect, the 1398 response is piggy-backed on the Acknowledgement message, and no 1399 separate message is required to return the response. 1401 Implementation Note: The protocol leaves the decision whether to 1402 piggy-back a response or not (i.e., send a separate response) to 1403 the server. The client MUST be prepared to receive either. On 1404 the quality of implementation level, there is a strong expectation 1405 that servers will implement code to piggy-back whenever possible 1406 -- saving resources in the network and both at the client and at 1407 the server. 1409 5.2.2. Separate 1411 It may not be possible to return a piggy-backed response in all 1412 cases. For example, a server might need longer to obtain the 1413 representation of the resource requested than it can wait sending 1414 back the Acknowledgement message, without risking the client to 1415 repeatedly retransmit the request message. The Response to a request 1416 carried in a Non-confirmable message is always sent separately (as 1417 there is no Acknowledgement message). 1419 The server maybe initiates the attempt to obtain the resource 1420 representation and times out an acknowledgement timer, or it 1421 immediately sends an acknowledgement knowing in advance that there 1422 will be no piggy-backed response. The acknowledgement effectively is 1423 a promise that the request will be acted upon. 1425 When the server finally has obtained the resource representation, it 1426 sends the response. When it is desired that this message is not 1427 lost, it is sent as a Confirmable message from the server to the 1428 client and answered by the client with an Acknowledgement, echoing 1429 the new Message ID chosen by the server. (It may also be sent as a 1430 Non-confirmable message; see Section 5.2.3.) 1432 When the server chooses to use a separate response, it sends the 1433 Acknowledgement to the Confirmable request as an empty message. If 1434 the server then sends a Confirmable response, the client's 1435 Acknowledgement to that response MUST also be an empty message (one 1436 that carries neither a request nor a response). The server MUST stop 1437 retransmitting its response on any matching Acknowledgement (silently 1438 ignoring any response code or payload) or Reset message. 1440 Implementation Notes: Note that, as the underlying datagram 1441 transport may not be sequence-preserving, the Confirmable message 1442 carrying the response may actually arrive before or after the 1443 Acknowledgement message for the request; for the purposes of 1444 terminating the retransmission sequence, this also serves as an 1445 acknowledgement. Note also that, while the CoAP protocol itself 1446 does not make any specific demands here, there is an expectation 1447 that the response will come within a time frame that is reasonable 1448 from an application point of view; as there is no underlying 1449 transport protocol that could be instructed to run a keep-alive 1450 mechanism, the requester may want to set up a timeout that is 1451 unrelated to CoAP's retransmission timers in case the server is 1452 destroyed or otherwise unable to send the response.) 1454 5.2.3. Non-confirmable 1456 If the request message is Non-confirmable, then the response SHOULD 1457 be returned in a Non-confirmable message as well. However, an 1458 endpoint MUST be prepared to receive a Non-confirmable response 1459 (preceded or followed by an empty Acknowledgement message) in reply 1460 to a Confirmable request, or a Confirmable response in reply to a 1461 Non-confirmable request. 1463 5.3. Request/Response Matching 1465 Regardless of how a response is sent, it is matched to the request by 1466 means of a token that is included by the client in the request, along 1467 with additional address information of the corresponding endpoint. 1469 5.3.1. Token 1471 The Token is used to match a response with a request. The token 1472 value is a sequence of 0 to 8 bytes. (Note that every message 1473 carries a token, even if it is of zero length.) Every request 1474 carries a client-generated token, which the server MUST echo in any 1475 resulting response without modification. 1477 A token is intended for use as a client-local identifier for 1478 differentiating between concurrent requests (see Section 5.3); it 1479 could have been called a "request ID". 1481 The client SHOULD generate tokens in such a way that tokens currently 1482 in use for a given source/destination endpoint pair are unique. 1483 (Note that a client implementation can use the same token for any 1484 request if it uses a different endpoint each time, e.g. a different 1485 source port number.) An empty token value is appropriate e.g. when 1486 no other tokens are in use to a destination, or when requests are 1487 made serially per destination and receive piggy-backed responses. 1488 There are however multiple possible implementation strategies to 1489 fulfill this. 1491 An endpoint receiving a token it did not generate MUST treat it as 1492 opaque and make no assumptions about its content or structure. 1494 5.3.2. Request/Response Matching Rules 1496 The exact rules for matching a response to a request are as follows: 1498 1. The source endpoint of the response MUST be the same as the 1499 destination endpoint of the original request. 1501 2. In a piggy-backed response, both the Message ID of the 1502 Confirmable request and the Acknowledgement, and the token of the 1503 response and original request MUST match. In a separate 1504 response, just the token of the response and original request 1505 MUST match. 1507 In case a message carrying a response is unexpected (the client is 1508 not waiting for a response from the identified endpoint, at the 1509 endpoint addressed, and/or with the given token), the response is 1510 rejected (Section 4.2, Section 4.3). 1512 Implementation Note: A client that receives a response in a CON 1513 message may want to clean up the message state right after sending 1514 the ACK. If that ACK is lost and the server retransmits the CON, 1515 the client may no longer have any state to correlate this response 1516 to, making the retransmission an unexpected message; the client 1517 may send a Reset message so it does not receive any more 1518 retransmissions. This behavior is normal and not an indication of 1519 an error. (Clients that are not aggressively optimized in their 1520 state memory usage will still have message state that will 1521 identify the second CON as a retransmission. Clients that 1522 actually expect more messages from the server 1523 [I-D.ietf-core-observe] will have to keep state in any case.) 1525 5.4. Options 1527 Both requests and responses may include a list of one or more 1528 options. For example, the URI in a request is transported in several 1529 options, and meta-data that would be carried in an HTTP header in 1530 HTTP is supplied as options as well. 1532 CoAP defines a single set of options that are used in both requests 1533 and responses: 1535 o Content-Format 1537 o ETag 1539 o Location-Path 1541 o Location-Query 1543 o Max-Age 1545 o Proxy-Uri 1547 o Proxy-Scheme 1548 o Uri-Host 1550 o Uri-Path 1552 o Uri-Port 1554 o Uri-Query 1556 o Accept 1558 o If-Match 1560 o If-None-Match 1562 The semantics of these options along with their properties are 1563 defined in detail in Section 5.10. 1565 Not all options are defined for use with all methods and response 1566 codes. The possible options for methods and response codes are 1567 defined in Section 5.8 and Section 5.9 respectively. In case an 1568 option is not defined for a method or response code, it MUST NOT be 1569 included by a sender and MUST be treated like an unrecognized option 1570 by a recipient. 1572 5.4.1. Critical/Elective 1574 Options fall into one of two classes: "critical" or "elective". The 1575 difference between these is how an option unrecognized by an endpoint 1576 is handled: 1578 o Upon reception, unrecognized options of class "elective" MUST be 1579 silently ignored. 1581 o Unrecognized options of class "critical" that occur in a 1582 Confirmable request MUST cause the return of a 4.02 (Bad Option) 1583 response. This response SHOULD include a diagnostic payload 1584 describing the unrecognized option(s) (see Section 5.5.2). 1586 o Unrecognized options of class "critical" that occur in a 1587 Confirmable response, or piggy-backed in an Acknowledgement, MUST 1588 cause the response to be rejected (Section 4.2). 1590 o Unrecognized options of class "critical" that occur in a Non- 1591 confirmable message MUST cause the message to be rejected 1592 (Section 4.3). 1594 Note that, whether critical or elective, an option is never 1595 "mandatory" (it is always optional): These rules are defined in order 1596 to enable implementations to stop processing options they do not 1597 understand or implement. 1599 Critical/Elective rules apply to non-proxying endpoints. A proxy 1600 processes options based on Unsafe/Safe classes as defined in 1601 Section 5.7. 1603 5.4.2. Proxy Unsafe/Safe and Cache-Key 1605 In addition to an option being marked as Critical or Elective, 1606 options are also classified based on how a proxy is to deal with the 1607 option if it does not recognize it. For this purpose, an option can 1608 either be considered Unsafe to Forward (UnSafe is set) or Safe to 1609 Forward (UnSafe is clear). 1611 In addition, for options that are marked Safe to Forward, the option 1612 indicates whether it is intended to be part of the Cache-Key in a 1613 request (some of the NoCacheKey bits are 0) or not (all NoCacheKey 1614 bits are 1; see Section 5.4.6). 1616 Note: The Cache-Key indication is relevant only for proxies that do 1617 not implement the given option as a request option and instead 1618 rely on the Safe/Unsafe indication only. E.g., for ETag, actually 1619 using the request option as a cache key is grossly inefficient, 1620 but it is the best thing one can do if ETag is not implemented by 1621 a proxy, as the response is going to differ based on the presence 1622 of the request option. A more useful proxy that does implement 1623 the ETag request option is not using ETag as a cache key. 1625 NoCacheKey is indicated in three bits so that only one out of 1626 eight codepoints is qualified as NoCacheKey, assuming this is the 1627 less likely case. 1629 Proxy behavior with regard to these classes is defined in 1630 Section 5.7. 1632 5.4.3. Length 1634 Option values are defined to have a specific length, often in the 1635 form of an upper and lower bound. If the length of an option value 1636 in a request is outside the defined range, that option MUST be 1637 treated like an unrecognized option (see Section 5.4.1). 1639 5.4.4. Default Values 1641 Options may be defined to have a default value. If the value of 1642 option is intended to be this default value, the option SHOULD NOT be 1643 included in the message. If the option is not present, the default 1644 value MUST be assumed. 1646 Where a critical option has a default value, this is chosen in such a 1647 way that the absence of the option in a message can be processed 1648 properly both by implementations unaware of the critical option and 1649 by implementations that interpret this absence as the presence of the 1650 default value for the option. 1652 5.4.5. Repeatable Options 1654 The definition of some options specifies that those options are 1655 repeatable. An option that is repeatable MAY be included one or more 1656 times in a message. An option that is not repeatable MUST NOT be 1657 included more than once in a message. 1659 If a message includes an option with more occurrences than the option 1660 is defined for, the additional option occurrences MUST be treated 1661 like an unrecognized option (see Section 5.4.1). 1663 5.4.6. Option Numbers 1665 An Option is identified by an option number, which also provides some 1666 additional semantics information: e.g., odd numbers indicate a 1667 critical option, while even numbers indicate an elective option. 1668 Note that this is not just a convention, it is a feature of the 1669 protocol: Whether an option is elective or critical is entirely 1670 determined by whether its option number is even or odd. 1672 More generally speaking, an Option number is constructed with a bit 1673 mask to indicate if an option is Critical/Elective, Unsafe/Safe and 1674 in the case of Safe, also a Cache-Key indication as shown by the 1675 following figure. When bit 7 (the least significant bit) is 1, an 1676 option is Critical (and likewise Elective when 0). When bit 6 is 1, 1677 an option is Unsafe (and likewise Safe when 0). When bit 6 is 0, 1678 i.e., the option is not Unsafe, it is not a Cache-Key (NoCacheKey) if 1679 and only if bits 3-5 are all set to 1; all other bit combinations 1680 mean that it indeed is a Cache-Key. These classes of options are 1681 explained in the next sections. 1683 0 1 2 3 4 5 6 7 1684 +---+---+---+---+---+---+---+---+ 1685 | | NoCacheKey| U | C | 1686 +---+---+---+---+---+---+---+---+ 1688 Figure 10: Option Number Mask 1690 An endpoint may use an equivalent of the C code in Figure 11 to 1691 derive the characteristics of an option number "onum". 1693 Critical = (onum & 1); 1694 UnSafe = (onum & 2); 1695 NoCacheKey = ((onum & 0x1e) == 0x1c); 1697 Figure 11: Determining Characteristics from an Option Number 1699 The option numbers for the options defined in this document are 1700 listed in the CoAP Option Number Registry (Section 12.2). 1702 5.5. Payloads and Representations 1704 Both requests and responses may include a payload, depending on the 1705 method or response code respectively. If a method or response code 1706 is not defined to have a payload, then a sender MUST NOT include one, 1707 and a recipient MUST ignore it. 1709 5.5.1. Representation 1711 The payload of requests or of responses indicating success is 1712 typically a representation of a resource or the result of the 1713 requested action. Its format is specified by the Internet media type 1714 and content coding given by the Content-Format Option. In the 1715 absence of this option, no default value is assumed and the format 1716 will need to be inferred by the application (e.g., from the 1717 application context). Payload "sniffing" SHOULD only be attempted if 1718 no content type is given. 1720 Implementation Note: On a quality of implementation level, there is 1721 a strong expectation that a Content-Format indication will be 1722 provided with resource representations whenever possible. This is 1723 not a "SHOULD"-level requirement solely because it is not a 1724 protocol requirement, and it also would be difficult to outline 1725 exactly in what cases this expectation can be violated. 1727 For responses indicating a client or server error, the payload is 1728 considered a representation of the result of the requested action 1729 only if a Content-Format Option is given. In the absence of this 1730 option, the payload is a Diagnostic Payload (Section 5.5.2). 1732 5.5.2. Diagnostic Payload 1734 If no Content-Format option is given, the payload of responses 1735 indicating a client or server error is a brief human-readable 1736 diagnostic message, explaining the error situation. This diagnostic 1737 message MUST be encoded using UTF-8 [RFC3629], more specifically 1738 using Net-Unicode form [RFC5198]. 1740 The message is similar to the Reason-Phrase on an HTTP status line. 1742 It is not intended for end-users but for software engineers that 1743 during debugging need to interpret it in the context of the present, 1744 English-language specification; therefore no mechanism for language 1745 tagging is needed or provided. In contrast to what is usual in HTTP, 1746 the payload SHOULD be empty if there is no additional information 1747 beyond the response code. 1749 5.5.3. Selected Representation 1751 Not all responses carry a payload that provides a representation of 1752 the resource addressed by the request. It is, however, sometimes 1753 useful to be able to refer to such a representation in relation to a 1754 response, independent of whether it actually was enclosed. 1756 We use the term "selected representation" to refer to the current 1757 representation of a target resource that would have been selected in 1758 a successful response if the corresponding request had used the 1759 method GET and excluded any conditional request options 1760 (Section 5.10.8). 1762 Certain response options provide metadata about the selected 1763 representation, which might differ from the representation included 1764 in the message for responses to some state-changing methods. Of the 1765 response options defined in this specification, only the ETag 1766 response option (Section 5.10.6) is defined as selected 1767 representation metadata. 1769 5.5.4. Content Negotiation 1771 A server may be able to supply a representation for a resource in one 1772 of multiple representation formats. Without further information from 1773 the client, it will provide the representation in the format it 1774 prefers. 1776 By using the Accept Option (Section 5.10.4) in a request, the client 1777 can indicate which content-format it prefers to receive. 1779 5.6. Caching 1781 CoAP endpoints MAY cache responses in order to reduce the response 1782 time and network bandwidth consumption on future, equivalent 1783 requests. 1785 The goal of caching in CoAP is to reuse a prior response message to 1786 satisfy a current request. In some cases, a stored response can be 1787 reused without the need for a network request, reducing latency and 1788 network round-trips; a "freshness" mechanism is used for this purpose 1789 (see Section 5.6.1). Even when a new request is required, it is 1790 often possible to reuse the payload of a prior response to satisfy 1791 the request, thereby reducing network bandwidth usage; a "validation" 1792 mechanism is used for this purpose (see Section 5.6.2). 1794 Unlike HTTP, the cacheability of CoAP responses does not depend on 1795 the request method, but the Response Code. The cacheability of each 1796 Response Code is defined along the Response Code definitions in 1797 Section 5.9. Response Codes that indicate success and are 1798 unrecognized by an endpoint MUST NOT be cached. 1800 For a presented request, a CoAP endpoint MUST NOT use a stored 1801 response, unless: 1803 o the presented request method and that used to obtain the stored 1804 response match, 1806 o all options match between those in the presented request and those 1807 of the request used to obtain the stored response (which includes 1808 the request URI), except that there is no need for a match of any 1809 request options marked as NoCacheKey (Section 5.4) or recognized 1810 by the Cache and fully interpreted with respect to its specified 1811 cache behavior (such as the ETag request option, Section 5.10.6, 1812 see also Section 5.4.2), and 1814 o the stored response is either fresh or successfully validated as 1815 defined below. 1817 5.6.1. Freshness Model 1819 When a response is "fresh" in the cache, it can be used to satisfy 1820 subsequent requests without contacting the origin server, thereby 1821 improving efficiency. 1823 The mechanism for determining freshness is for an origin server to 1824 provide an explicit expiration time in the future, using the Max-Age 1825 Option (see Section 5.10.5). The Max-Age Option indicates that the 1826 response is to be considered not fresh after its age is greater than 1827 the specified number of seconds. 1829 The Max-Age Option defaults to a value of 60. Thus, if it is not 1830 present in a cacheable response, then the response is considered not 1831 fresh after its age is greater than 60 seconds. If an origin server 1832 wishes to prevent caching, it MUST explicitly include a Max-Age 1833 Option with a value of zero seconds. 1835 If a client has a fresh stored response and makes a new request 1836 matching the request for that stored response, the new response 1837 invalidates the old response. 1839 5.6.2. Validation Model 1841 When an endpoint has one or more stored responses for a GET request, 1842 but cannot use any of them (e.g., because they are not fresh), it can 1843 use the ETag Option (Section 5.10.6) in the GET request to give the 1844 origin server an opportunity to both select a stored response to be 1845 used, and to update its freshness. This process is known as 1846 "validating" or "revalidating" the stored response. 1848 When sending such a request, the endpoint SHOULD add an ETag Option 1849 specifying the entity-tag of each stored response that is applicable. 1851 A 2.03 (Valid) response indicates the stored response identified by 1852 the entity-tag given in the response's ETag Option can be reused, 1853 after updating it as described in Section 5.9.1.3. 1855 Any other response code indicates that none of the stored responses 1856 nominated in the request is suitable. Instead, the response SHOULD 1857 be used to satisfy the request and MAY replace the stored response. 1859 5.7. Proxying 1861 A proxy is a CoAP endpoint that can be tasked by CoAP clients to 1862 perform requests on their behalf. This may be useful, for example, 1863 when the request could otherwise not be made, or to service the 1864 response from a cache in order to reduce response time and network 1865 bandwidth or energy consumption. 1867 In an overall architecture for a Constrained RESTful Environment, 1868 proxies can serve quite different purposes. Proxies can be 1869 explicitly selected by clients, a role that we term "forward-proxy". 1870 Proxies can also be inserted to stand in for origin servers, a role 1871 that we term "reverse-proxy". Orthogonal to this distinction, a 1872 proxy can map from a CoAP request to a CoAP request (CoAP-to-CoAP 1873 proxy) or translate from or to a different protocol ("cross-proxy"). 1874 Full definitions of these terms are provided in Section 1.2. 1876 Notes: The terminology in this specification has been selected to be 1877 culturally compatible with the terminology used in the wider Web 1878 application environments, without necessarily matching it in every 1879 detail (which may not even be relevant to Constrained RESTful 1880 Environments). Not too much semantics should be ascribed to the 1881 components of the terms (such as "forward", "reverse", or 1882 "cross"). 1884 HTTP proxies, besides acting as HTTP proxies, often offer a 1885 transport protocol proxying function ("CONNECT") to enable end-to- 1886 end transport layer security through the proxy. No such function 1887 is defined for CoAP-to-CoAP proxies in this specification, as 1888 forwarding of UDP packets is unlikely to be of much value in 1889 Constrained RESTful environments. See also Section 10.2.7 for the 1890 cross-proxy case. 1892 5.7.1. Proxy Operation 1894 A proxy generally needs a way to determine potential request 1895 parameters for a request to a destination based on the request it 1896 received. This way is fully specified for a forward-proxy, but may 1897 depend on the specific configuration for a reverse-proxy. In 1898 particular, the client of a reverse-proxy generally does not indicate 1899 a locator for the destination, necessitating some form of namespace 1900 translation in the reverse-proxy. However, some aspects of the 1901 operation of proxies are common to all its forms. 1903 If a proxy does not employ a cache, then it simply forwards the 1904 translated request to the determined destination. Otherwise, if it 1905 does employ a cache but does not have a stored response that matches 1906 the translated request and is considered fresh, then it needs to 1907 refresh its cache according to Section 5.6. For options in the 1908 request that the proxy recognizes, it knows whether the option is 1909 intended to act as part of the key used in looking up the cached 1910 value or not. E.g., since requests for different Uri-Path values 1911 address different resources, Uri-Path values are always parts of the 1912 cache key, while, e.g., Token values are never part of the cache key. 1913 For options that the proxy does not recognize but that are marked 1914 Safe in the option number, the option also indicates whether it is to 1915 be included in the cache key (NoCacheKey is not all set) or not 1916 (NoCacheKey is all set). (Options that are unrecognized and marked 1917 Unsafe lead to 4.02 Bad Option.) 1919 If the request to the destination times out, then a 5.04 (Gateway 1920 Timeout) response MUST be returned. If the request to the 1921 destination returns a response that cannot be processed by the proxy 1922 (e.g, due to unrecognized critical options, message format errors), 1923 then a 5.02 (Bad Gateway) response MUST be returned. Otherwise, the 1924 proxy returns the response to the client. 1926 If a response is generated out of a cache, it MUST be generated with 1927 a Max-Age Option that does not extend the max-age originally set by 1928 the server, considering the time the resource representation spent in 1929 the cache. E.g., the Max-Age Option could be adjusted by the proxy 1930 for each response using the formula: 1932 proxy-max-age = original-max-age - cache-age 1934 For example if a request is made to a proxied resource that was 1935 refreshed 20 seconds ago and had an original Max-Age of 60 seconds, 1936 then that resource's proxied max-age is now 40 seconds. Considering 1937 potential network delays on the way from the origin server, a proxy 1938 SHOULD be conservative in the max-age values offered. 1940 All options present in a proxy request MUST be processed at the 1941 proxy. Unsafe options in a request that are not recognized by the 1942 proxy MUST lead to a 4.02 (Bad Option) response being returned by the 1943 proxy. A CoAP-to-CoAP proxy MUST forward to the origin server all 1944 Safe options that it does not recognize. Similarly, Unsafe options 1945 in a response that are not recognized by the CoAP-to-CoAP proxy 1946 server MUST lead to a 5.02 (Bad Gateway) response. Again, Safe 1947 options that are not recognized MUST be forwarded. 1949 Additional considerations for cross-protocol proxying between CoAP 1950 and HTTP are discussed in Section 10. 1952 5.7.2. Forward-Proxies 1954 CoAP distinguishes between requests made (as if) to an origin server 1955 and a request made through a forward-proxy. CoAP requests to a 1956 forward-proxy are made as normal Confirmable or Non-confirmable 1957 requests to the forward-proxy endpoint, but specify the request URI 1958 in a different way: The request URI in a proxy request is specified 1959 as a string in the Proxy-Uri Option (see Section 5.10.2), while the 1960 request URI in a request to an origin server is split into the Uri- 1961 Host, Uri-Port, Uri-Path and Uri-Query Options (see Section 5.10.1); 1962 alternatively the URI in a proxy request can be assembled from a 1963 Proxy-Scheme option and the split options mentioned. 1965 When a proxy request is made to an endpoint and the endpoint is 1966 unwilling or unable to act as proxy for the request URI, it MUST 1967 return a 5.05 (Proxying Not Supported) response. If the authority 1968 (host and port) is recognized as identifying the proxy endpoint 1969 itself (see Section 5.10.2), then the request MUST be treated as a 1970 local (non-proxied) request. 1972 Unless a proxy is configured to forward the proxy request to another 1973 proxy, it MUST translate the request as follows: The scheme of the 1974 request URI defines the outgoing protocol and its details (e.g., CoAP 1975 is used over UDP for the "coap" scheme and over DTLS for the "coaps" 1976 scheme.) For a CoAP-to-CoAP proxy, the origin server's IP address 1977 and port are determined by the authority component of the request 1978 URI, and the request URI is decoded and split into the Uri-Host, Uri- 1979 Port, Uri-Path and Uri-Query Options. This consumes the Proxy-Uri or 1980 Proxy-Scheme option, which is therefore not forwarded to the origin 1981 server. 1983 5.7.3. Reverse-Proxies 1985 Reverse-proxies do not make use of the Proxy-Uri or Proxy-Scheme 1986 options, but need to determine the destination (next hop) of a 1987 request from information in the request and information in their 1988 configuration. E.g., a reverse-proxy might offer various resources 1989 the existence of which it has learned through resource discovery as 1990 if they were its own resources. The reverse-proxy is free to build a 1991 namespace for the URIs that identify these resources. A reverse- 1992 proxy may also build a namespace that gives the client more control 1993 over where the request goes, e.g. by embedding host identifiers and 1994 port numbers into the URI path of the resources offered. 1996 In processing the response, a reverse-proxy has to be careful that 1997 ETag option values from different sources are not mixed up on one 1998 resource offered to its clients. In many cases, the ETag can be 1999 forwarded unchanged. If the mapping from a resource offered by the 2000 reverse-proxy to resources offered by its various origin servers is 2001 not unique, the reverse-proxy may need to generate a new ETag, making 2002 sure the semantics of this option are properly preserved. 2004 5.8. Method Definitions 2006 In this section each method is defined along with its behavior. A 2007 request with an unrecognized or unsupported Method Code MUST generate 2008 a 4.05 (Method Not Allowed) piggy-backed response. 2010 5.8.1. GET 2012 The GET method retrieves a representation for the information that 2013 currently corresponds to the resource identified by the request URI. 2014 If the request includes an Accept Option, that indicates the 2015 preferred content-format of a response. If the request includes an 2016 ETag Option, the GET method requests that ETag be validated and that 2017 the representation be transferred only if validation failed. Upon 2018 success a 2.05 (Content) or 2.03 (Valid) response code SHOULD be 2019 present in the response. 2021 The GET method is safe and idempotent. 2023 5.8.2. POST 2025 The POST method requests that the representation enclosed in the 2026 request be processed. The actual function performed by the POST 2027 method is determined by the origin server and dependent on the target 2028 resource. It usually results in a new resource being created or the 2029 target resource being updated. 2031 If a resource has been created on the server, the response returned 2032 by the server SHOULD have a 2.01 (Created) response code and SHOULD 2033 include the URI of the new resource in a sequence of one or more 2034 Location-Path and/or Location-Query Options (Section 5.10.7). If the 2035 POST succeeds but does not result in a new resource being created on 2036 the server, the response SHOULD have a 2.04 (Changed) response code. 2037 If the POST succeeds and results in the target resource being 2038 deleted, the response SHOULD have a 2.02 (Deleted) response code. 2040 POST is neither safe nor idempotent. 2042 5.8.3. PUT 2044 The PUT method requests that the resource identified by the request 2045 URI be updated or created with the enclosed representation. The 2046 representation format is specified by the media type and content 2047 coding given in the Content-Format Option, if provided. 2049 If a resource exists at the request URI the enclosed representation 2050 SHOULD be considered a modified version of that resource, and a 2.04 2051 (Changed) response code SHOULD be returned. If no resource exists 2052 then the server MAY create a new resource with that URI, resulting in 2053 a 2.01 (Created) response code. If the resource could not be created 2054 or modified, then an appropriate error response code SHOULD be sent. 2056 Further restrictions to a PUT can be made by including the If-Match 2057 (see Section 5.10.8.1) or If-None-Match (see Section 5.10.8.2) 2058 options in the request. 2060 PUT is not safe, but is idempotent. 2062 5.8.4. DELETE 2064 The DELETE method requests that the resource identified by the 2065 request URI be deleted. A 2.02 (Deleted) response code SHOULD be 2066 used on success or in case the resource did not exist before the 2067 request. 2069 DELETE is not safe, but is idempotent. 2071 5.9. Response Code Definitions 2073 Each response code is described below, including any options required 2074 in the response. Where appropriate, some of the codes will be 2075 specified in regards to related response codes in HTTP [RFC2616]; 2076 this does not mean that any such relationship modifies the HTTP 2077 mapping specified in Section 10. 2079 5.9.1. Success 2.xx 2081 This class of status code indicates that the clients request was 2082 successfully received, understood, and accepted. 2084 5.9.1.1. 2.01 Created 2086 Like HTTP 201 "Created", but only used in response to POST and PUT 2087 requests. The payload returned with the response, if any, is a 2088 representation of the action result. 2090 If the response includes one or more Location-Path and/or Location- 2091 Query Options, the values of these options specify the location at 2092 which the resource was created. Otherwise, the resource was created 2093 at the request URI. A cache receiving this response MUST mark any 2094 stored response for the created resource as not fresh. 2096 This response is not cacheable. 2098 5.9.1.2. 2.02 Deleted 2100 Like HTTP 204 "No Content", but only used in response to DELETE 2101 requests. The payload returned with the response, if any, is a 2102 representation of the action result. 2104 This response is not cacheable. However, a cache MUST mark any 2105 stored response for the deleted resource as not fresh. 2107 5.9.1.3. 2.03 Valid 2109 Related to HTTP 304 "Not Modified", but only used to indicate that 2110 the response identified by the entity-tag identified by the included 2111 ETag Option is valid. Accordingly, the response MUST include an ETag 2112 Option, and MUST NOT include a payload. 2114 When a cache that recognizes and processes the ETag response option 2115 receives a 2.03 (Valid) response, it MUST update the stored response 2116 with the value of the Max-Age Option included in the response 2117 (explicitly, or implicitly as a default value; see also 2118 Section 5.6.2). For each type of Safe option present in the 2119 response, the (possibly empty) set of options of this type that are 2120 present in the stored response MUST be replaced with the set of 2121 options of this type in the response received. (Unsafe options may 2122 trigger similar option specific processing as defined by the option.) 2124 5.9.1.4. 2.04 Changed 2126 Like HTTP 204 "No Content", but only used in response to POST and PUT 2127 requests. The payload returned with the response, if any, is a 2128 representation of the action result. 2130 This response is not cacheable. However, a cache MUST mark any 2131 stored response for the changed resource as not fresh. 2133 5.9.1.5. 2.05 Content 2135 Like HTTP 200 "OK", but only used in response to GET requests. 2137 The payload returned with the response is a representation of the 2138 target resource. 2140 This response is cacheable: Caches can use the Max-Age Option to 2141 determine freshness (see Section 5.6.1) and (if present) the ETag 2142 Option for validation (see Section 5.6.2). 2144 5.9.2. Client Error 4.xx 2146 This class of response code is intended for cases in which the client 2147 seems to have erred. These response codes are applicable to any 2148 request method. 2150 The server SHOULD include a diagnostic payload under the conditions 2151 detailed in Section 5.5.2. 2153 Responses of this class are cacheable: Caches can use the Max-Age 2154 Option to determine freshness (see Section 5.6.1). They cannot be 2155 validated. 2157 5.9.2.1. 4.00 Bad Request 2159 Like HTTP 400 "Bad Request". 2161 5.9.2.2. 4.01 Unauthorized 2163 The client is not authorized to perform the requested action. The 2164 client SHOULD NOT repeat the request without previously improving its 2165 authentication status to the server. Which specific mechanism can be 2166 used for this is outside this document's scope; see also Section 9. 2168 5.9.2.3. 4.02 Bad Option 2170 The request could not be understood by the server due to one or more 2171 unrecognized or malformed options. The client SHOULD NOT repeat the 2172 request without modification. 2174 5.9.2.4. 4.03 Forbidden 2176 Like HTTP 403 "Forbidden". 2178 5.9.2.5. 4.04 Not Found 2180 Like HTTP 404 "Not Found". 2182 5.9.2.6. 4.05 Method Not Allowed 2184 Like HTTP 405 "Method Not Allowed", but with no parallel to the 2185 "Allow" header field. 2187 5.9.2.7. 4.06 Not Acceptable 2189 Like HTTP 406 "Not Acceptable", but with no response entity. 2191 5.9.2.8. 4.12 Precondition Failed 2193 Like HTTP 412 "Precondition Failed". 2195 5.9.2.9. 4.13 Request Entity Too Large 2197 Like HTTP 413 "Request Entity Too Large". 2199 5.9.2.10. 4.15 Unsupported Content-Format 2201 Like HTTP 415 "Unsupported Media Type". 2203 5.9.3. Server Error 5.xx 2205 This class of response code indicates cases in which the server is 2206 aware that it has erred or is incapable of performing the request. 2207 These response codes are applicable to any request method. 2209 The server SHOULD include a diagnostic payload under the conditions 2210 detailed in Section 5.5.2. 2212 Responses of this class are cacheable: Caches can use the Max-Age 2213 Option to determine freshness (see Section 5.6.1). They cannot be 2214 validated. 2216 5.9.3.1. 5.00 Internal Server Error 2218 Like HTTP 500 "Internal Server Error". 2220 5.9.3.2. 5.01 Not Implemented 2222 Like HTTP 501 "Not Implemented". 2224 5.9.3.3. 5.02 Bad Gateway 2226 Like HTTP 502 "Bad Gateway". 2228 5.9.3.4. 5.03 Service Unavailable 2230 Like HTTP 503 "Service Unavailable", but using the Max-Age Option in 2231 place of the "Retry-After" header field to indicate the number of 2232 seconds after which to retry. 2234 5.9.3.5. 5.04 Gateway Timeout 2236 Like HTTP 504 "Gateway Timeout". 2238 5.9.3.6. 5.05 Proxying Not Supported 2240 The server is unable or unwilling to act as a forward-proxy for the 2241 URI specified in the Proxy-Uri Option or using Proxy-Scheme (see 2242 Section 5.10.2). 2244 5.10. Option Definitions 2246 The individual CoAP options are summarized in Table 3 and explained 2247 in the subsections of this section. 2249 In this table, the C, U, and N columns indicate the properties, 2250 Critical, UnSafe, and NoCacheKey, respectively. Since NoCacheKey 2251 only has a meaning for options that are safe to foward (not marked 2252 Unsafe), the column is filled with a dash for UnSafe options. (The 2253 present specification does not define any NoCacheKey options, but the 2254 format of the table is intended to be useful for additional 2255 specifications.) 2256 +-----+---+---+---+---+----------------+--------+--------+----------+ 2257 | No. | C | U | N | R | Name | Format | Length | Default | 2258 +-----+---+---+---+---+----------------+--------+--------+----------+ 2259 | 1 | x | | | x | If-Match | opaque | 0-8 | (none) | 2260 | 3 | x | x | - | | Uri-Host | string | 1-255 | (see | 2261 | | | | | | | | | below) | 2262 | 4 | | | | x | ETag | opaque | 1-8 | (none) | 2263 | 5 | x | | | | If-None-Match | empty | 0 | (none) | 2264 | 7 | x | x | - | | Uri-Port | uint | 0-2 | (see | 2265 | | | | | | | | | below) | 2266 | 8 | | | | x | Location-Path | string | 0-255 | (none) | 2267 | 11 | x | x | - | x | Uri-Path | string | 0-255 | (none) | 2268 | 12 | | | | | Content-Format | uint | 0-2 | (none) | 2269 | 14 | | x | - | | Max-Age | uint | 0-4 | 60 | 2270 | 15 | x | x | - | x | Uri-Query | string | 0-255 | (none) | 2271 | 16 | | | | | Accept | uint | 0-2 | (none) | 2272 | 20 | | | | x | Location-Query | string | 0-255 | (none) | 2273 | 35 | x | x | - | | Proxy-Uri | string | 1-1034 | (none) | 2274 | 39 | x | x | - | | Proxy-Scheme | string | 1-255 | (none) | 2275 +-----+---+---+---+---+----------------+--------+--------+----------+ 2277 C=Critical, U=Unsafe, N=No-Cache-Key, R=Repeatable 2279 Table 3: Options 2281 5.10.1. Uri-Host, Uri-Port, Uri-Path and Uri-Query 2283 The Uri-Host, Uri-Port, Uri-Path and Uri-Query Options are used to 2284 specify the target resource of a request to a CoAP origin server. 2285 The options encode the different components of the request URI in a 2286 way that no percent-encoding is visible in the option values and that 2287 the full URI can be reconstructed at any involved endpoint. The 2288 syntax of CoAP URIs is defined in Section 6. 2290 The steps for parsing URIs into options is defined in Section 6.4. 2291 These steps result in zero or more Uri-Host, Uri-Port, Uri-Path and 2292 Uri-Query Options being included in a request, where each option 2293 holds the following values: 2295 o the Uri-Host Option specifies the Internet host of the resource 2296 being requested, 2298 o the Uri-Port Option specifies the transport layer port number of 2299 the resource, 2301 o each Uri-Path Option specifies one segment of the absolute path to 2302 the resource, and 2304 o each Uri-Query Option specifies one argument parameterizing the 2305 resource. 2307 Note: Fragments ([RFC3986], Section 3.5) are not part of the request 2308 URI and thus will not be transmitted in a CoAP request. 2310 The default value of the Uri-Host Option is the IP literal 2311 representing the destination IP address of the request message. 2312 Likewise, the default value of the Uri-Port Option is the destination 2313 UDP port. The default values for the Uri-Host and Uri-Port Options 2314 are sufficient for requests to most servers. Explicit Uri-Host and 2315 Uri-Port Options are typically used when an endpoint hosts multiple 2316 virtual servers. 2318 The Uri-Path and Uri-Query Option can contain any character sequence. 2319 No percent-encoding is performed. The value of a Uri-Path Option 2320 MUST NOT be "." or ".." (as the request URI must be resolved before 2321 parsing it into options). 2323 The steps for constructing the request URI from the options are 2324 defined in Section 6.5. Note that an implementation does not 2325 necessarily have to construct the URI; it can simply look up the 2326 target resource by looking at the individual options. 2328 Examples can be found in Appendix B. 2330 5.10.2. Proxy-Uri and Proxy-Scheme 2332 The Proxy-Uri Option is used to make a request to a forward-proxy 2333 (see Section 5.7). The forward-proxy is requested to forward the 2334 request or service it from a valid cache, and return the response. 2336 The option value is an absolute-URI ([RFC3986], Section 4.3). 2338 Note that the forward-proxy MAY forward the request on to another 2339 proxy or directly to the server specified by the absolute-URI. In 2340 order to avoid request loops, a proxy MUST be able to recognize all 2341 of its server names, including any aliases, local variations, and the 2342 numeric IP addresses. 2344 An endpoint receiving a request with a Proxy-Uri Option that is 2345 unable or unwilling to act as a forward-proxy for the request MUST 2346 cause the return of a 5.05 (Proxying Not Supported) response. 2348 The Proxy-Uri Option MUST take precedence over any of the Uri-Host, 2349 Uri-Port, Uri-Path or Uri-Query options (which MUST NOT be included 2350 at the same time in a request containing the Proxy-Uri Option). 2352 As a special case to simplify many proxy clients, the absolute-URI 2353 can be constructed from the Uri-* options. When a Proxy-Scheme 2354 Option is present, the absolute-URI is constructed as follows: A CoAP 2355 URI is constructed from the Uri-* options as defined in Section 6.5. 2356 In the resulting URI, the initial scheme up to, but not including the 2357 following colon is then replaced by the content of the Proxy-Scheme 2358 Option. 2360 5.10.3. Content-Format 2362 The Content-Format Option indicates the representation format of the 2363 message payload. The representation format is given as a numeric 2364 content format identifier that is defined in the CoAP Content Format 2365 registry (Section 12.3). In the absence of the option, no default 2366 value is assumed, i.e. the representation format of any 2367 representation message payload is indeterminate (Section 5.5). 2369 5.10.4. Accept 2371 The CoAP Accept option can be used to indicate which Content-Format 2372 is acceptable to the client. The representation format is given as a 2373 numeric Content-Format identifier that is defined in the CoAP 2374 Content-Format registry (Section 12.3). If no Accept option is 2375 given, the client does not express a preference (thus no default 2376 value is assumed). The client prefers the representation returned by 2377 the server to be in the Content-Format indicated. The server SHOULD 2378 return the preferred Content-Format if available. If the preferred 2379 Content-Format cannot be returned, then a 4.06 "Not Acceptable" 2380 SHOULD be sent as a response. 2382 Note that as a server might not support the Accept option (and thus 2383 would ignore it as it is elective), the client needs to be prepared 2384 to receive a representation in a different Content-Format. The 2385 client can simply discard a representation it can not make use of. 2387 5.10.5. Max-Age 2389 The Max-Age Option indicates the maximum time a response may be 2390 cached before it MUST be considered not fresh (see Section 5.6.1). 2392 The option value is an integer number of seconds between 0 and 2393 2**32-1 inclusive (about 136.1 years). A default value of 60 seconds 2394 is assumed in the absence of the option in a response. 2396 The value is intended to be current at the time of transmission. 2397 Servers that provide resources with strict tolerances on the value of 2398 Max-Age SHOULD update the value before each retransmission. (See 2399 also Section 5.7.1.) 2401 5.10.6. ETag 2403 An entity-tag is intended for use as a resource-local identifier for 2404 differentiating between representations of the same resource that 2405 vary over time. It is generated by the server providing the 2406 resource, which may generate it in any number of ways including a 2407 version, checksum, hash or time. An endpoint receiving an entity-tag 2408 MUST treat it as opaque and make no assumptions about its content or 2409 structure. (Endpoints that generate an entity-tag are encouraged to 2410 use the most compact representation possible, in particular in 2411 regards to clients and intermediaries that may want to store multiple 2412 ETag values.) 2414 5.10.6.1. ETag as a Response Option 2416 The ETag Option in a response provides the current value (i.e., after 2417 the request was processed) of the entity-tag for the "tagged 2418 representation". If no Location-* options are present, the tagged 2419 representation is the selected representation (Section 5.5.3) of the 2420 target resource. If one or more Location-* options are present and 2421 thus a location URI is indicated (Section 5.10.7), the tagged 2422 representation is the representation that would be retrieved by a GET 2423 request to the location URI. 2425 An ETag response option can be included with any response for which 2426 there is a tagged representation (e.g., it would not be meaningful in 2427 a 4.04 or 4.00 response). The ETag Option MUST NOT occur more than 2428 once in a response. 2430 There is no default value for the ETag Option; if it is not present 2431 in a response, the server makes no statement about the entity-tag for 2432 the tagged representation. 2434 5.10.6.2. ETag as a Request Option 2436 In a GET request, an endpoint that has one or more representations 2437 previously obtained from the resource, and has obtained ETag response 2438 options with these, can specify an instance of the ETag Option for 2439 one or more of these stored responses. 2441 A server can issue a 2.03 Valid response (Section 5.9.1.3) in place 2442 of a 2.05 Content response if one of the ETags given is the entity- 2443 tag for the current representation, i.e. is valid; the 2.03 Valid 2444 response then echoes this specific ETag in a response option. 2446 In effect, a client can determine if any of the stored 2447 representations is current (see Section 5.6.2) without needing to 2448 transfer them again. 2450 The ETag Option MAY occur zero, one or more times in a request. 2452 5.10.7. Location-Path and Location-Query 2454 The Location-Path and Location-Query Options together indicate a 2455 relative URI that consists either of an absolute path, a query string 2456 or both. A combination of these options is included in a 2.01 2457 (Created) response to indicate the location of the resource created 2458 as the result of a POST request (see Section 5.8.2). The location is 2459 resolved relative to the request URI. 2461 If a response with one or more Location-Path and/or Location-Query 2462 Options passes through a cache that interprets these options and the 2463 implied URI identifies one or more currently stored responses, those 2464 entries MUST be marked as not fresh. 2466 Each Location-Path Option specifies one segment of the absolute path 2467 to the resource, and each Location-Query Option specifies one 2468 argument parameterizing the resource. The Location-Path and 2469 Location-Query Option can contain any character sequence. No 2470 percent-encoding is performed. The value of a Location-Path Option 2471 MUST NOT be "." or "..". 2473 The steps for constructing the location URI from the options are 2474 analogous to Section 6.5, except that the first five steps are 2475 skipped and the result is a relative URI-reference, which is then 2476 interpreted relative to the request URI. Note that the relative URI- 2477 reference constructed this way always includes an absolute-path 2478 (e.g., leaving out Location-Path but supplying Location-Query means 2479 the path component in the URI is "/"). 2481 The options that are used to compute the relative URI-reference are 2482 collectively called Location-* options. Beyond Location-Path and 2483 Location-Query, more Location-* options may be defined in the future, 2484 and have been reserved option numbers 128, 132, 136, and 140. If any 2485 of these reserved option numbers occurs in addition to Location-Path 2486 and/or Location-Query and are not supported, then a 4.02 (Bad Option) 2487 error MUST be returned. 2489 5.10.8. Conditional Request Options 2491 Conditional request options enable a client to ask the server to 2492 perform the request only if certain conditions specified by the 2493 option are fulfilled. 2495 For each of these options, if the condition given is not fulfilled, 2496 then the the server MUST NOT perform the requested method. Instead, 2497 the server MUST respond with the 4.12 (Precondition Failed) response 2498 code. 2500 If the condition is fulfilled, the server performs the request method 2501 as if the conditional request options were not present. 2503 If the request would, without the conditional request options, result 2504 in anything other than a 2.xx or 4.12 response code, then any 2505 conditional request options MAY be ignored. 2507 5.10.8.1. If-Match 2509 The If-Match Option MAY be used to make a request conditional on the 2510 current existence or value of an ETag for one or more representations 2511 of the target resource. If-Match is generally useful for resource 2512 update requests, such as PUT requests, as a means for protecting 2513 against accidental overwrites when multiple clients are acting in 2514 parallel on the same resource (i.e., the "lost update" problem). 2516 The value of an If-Match option is either an ETag or the empty 2517 string. An If-Match option with an ETag matches a representation 2518 with that exact ETag. An If-Match option with an empty value matches 2519 any existing representation (i.e., it places the precondition on the 2520 existence of any current representation for the target resource). 2522 The If-Match Option can occur multiple times. If any of the options 2523 match, then the condition is fulfilled. 2525 If there is one or more If-Match Option, but none of the options 2526 match, then the condition is not fulfilled. 2528 5.10.8.2. If-None-Match 2530 The If-None-Match Option MAY be used to make a request conditional on 2531 the non-existence of the target resource. If-None-Match is useful 2532 for resource creation requests, such as PUT requests, as a means for 2533 protecting against accidental overwrites when multiple clients are 2534 acting in parallel on the same resource. The If-None-Match Option 2535 carries no value. 2537 If the target resource does exist, then the condition is not 2538 fulfilled. 2540 6. CoAP URIs 2542 CoAP uses the "coap" and "coaps" URI schemes for identifying CoAP 2543 resources and providing a means of locating the resource. Resources 2544 are organized hierarchically and governed by a potential CoAP origin 2545 server listening for CoAP requests ("coap") or DTLS-secured CoAP 2546 requests ("coaps") on a given UDP port. The CoAP server is 2547 identified via the generic syntax's authority component, which 2548 includes a host component and optional UDP port number. The 2549 remainder of the URI is considered to be identifying a resource which 2550 can be operated on by the methods defined by the CoAP protocol. The 2551 "coap" and "coaps" URI schemes can thus be compared to the "http" and 2552 "https" URI schemes respectively. 2554 The syntax of the "coap" and "coaps" URI schemes is specified in this 2555 section in Augmented Backus-Naur Form (ABNF) [RFC5234]. The 2556 definitions of "host", "port", "path-abempty", "query", "segment", 2557 "IP-literal", "IPv4address" and "reg-name" are adopted from 2558 [RFC3986]. 2560 Implementation Note: Unfortunately, over time the URI format has 2561 acquired significant complexity. Implementers are encouraged to 2562 examine [RFC3986] closely. E.g., the ABNF for IPv6 addresses is 2563 more complicated than maybe expected. Also, implementers should 2564 take care to perform the processing of percent decoding/encoding 2565 exactly once on the way from a URI to its decoded components or 2566 back. Percent encoding is crucial for data transparency, but may 2567 lead to unusual results such as a slash in a path component. 2569 6.1. coap URI Scheme 2571 coap-URI = "coap:" "//" host [ ":" port ] path-abempty [ "?" query ] 2573 If the host component is provided as an IP-literal or IPv4address, 2574 then the CoAP server can be reached at that IP address. If host is a 2575 registered name, then that name is considered an indirect identifier 2576 and the endpoint might use a name resolution service, such as DNS, to 2577 find the address of that host. The host MUST NOT be empty; if a URI 2578 is received with a missing authority or an empty host, then it MUST 2579 be considered invalid. The port subcomponent indicates the UDP port 2580 at which the CoAP server is located. If it is empty or not given, 2581 then the default port 5683 is assumed. 2583 The path identifies a resource within the scope of the host and port. 2584 It consists of a sequence of path segments separated by a slash 2585 character (U+002F SOLIDUS "/"). 2587 The query serves to further parameterize the resource. It consists 2588 of a sequence of arguments separated by an ampersand character 2589 (U+0026 AMPERSAND "&"). An argument is often in the form of a 2590 "key=value" pair. 2592 The "coap" URI scheme supports the path prefix "/.well-known/" 2593 defined by [RFC5785] for "well-known locations" in the name-space of 2594 a host. This enables discovery of policy or other information about 2595 a host ("site-wide metadata"), such as hosted resources (see 2596 Section 7). 2598 Application designers are encouraged to make use of short, but 2599 descriptive URIs. As the environments that CoAP is used in are 2600 usually constrained for bandwidth and energy, the trade-off between 2601 these two qualities should lean towards the shortness, without 2602 ignoring descriptiveness. 2604 6.2. coaps URI Scheme 2606 coaps-URI = "coaps:" "//" host [ ":" port ] path-abempty 2607 [ "?" query ] 2609 All of the requirements listed above for the "coap" scheme are also 2610 requirements for the "coaps" scheme, except that a default UDP port 2611 of [IANA_TBD_PORT] is assumed if the port subcomponent is empty or 2612 not given, and the UDP datagrams MUST be secured for privacy through 2613 the use of DTLS as described in Section 9.1. 2615 Considerations for caching of responses to "coaps" identified 2616 requests are discussed in Section 11.2. 2618 Resources made available via the "coaps" scheme have no shared 2619 identity with the "coap" scheme even if their resource identifiers 2620 indicate the same authority (the same host listening to the same UDP 2621 port). They are distinct name spaces and are considered to be 2622 distinct origin servers. 2624 6.3. Normalization and Comparison Rules 2626 Since the "coap" and "coaps" schemes conform to the URI generic 2627 syntax, such URIs are normalized and compared according to the 2628 algorithm defined in [RFC3986], Section 6, using the defaults 2629 described above for each scheme. 2631 If the port is equal to the default port for a scheme, the normal 2632 form is to elide the port subcomponent. Likewise, an empty path 2633 component is equivalent to an absolute path of "/", so the normal 2634 form is to provide a path of "/" instead. The scheme and host are 2635 case-insensitive and normally provided in lowercase; IP-literals are 2636 in recommended form [RFC5952]; all other components are compared in a 2637 case-sensitive manner. Characters other than those in the "reserved" 2638 set are equivalent to their percent-encoded octets (see [RFC3986], 2639 Section 2.1): the normal form is to not encode them. 2641 For example, the following three URIs are equivalent, and cause the 2642 same options and option values to appear in the CoAP messages: 2644 coap://example.com:5683/~sensors/temp.xml 2645 coap://EXAMPLE.com/%7Esensors/temp.xml 2646 coap://EXAMPLE.com:/%7esensors/temp.xml 2648 6.4. Decomposing URIs into Options 2650 The steps to parse a request's options from a string /url/ are as 2651 follows. These steps either result in zero or more of the Uri-Host, 2652 Uri-Port, Uri-Path and Uri-Query Options being included in the 2653 request, or they fail. 2655 1. If the /url/ string is not an absolute URI ([RFC3986]), then fail 2656 this algorithm. 2658 2. Resolve the /url/ string using the process of reference 2659 resolution defined by [RFC3986], with the URL character encoding 2660 set to UTF-8 [RFC3629]. 2662 NOTE: It doesn't matter what it is resolved relative to, since we 2663 already know it is an absolute URL at this point. 2665 3. If /url/ does not have a component whose value, when 2666 converted to ASCII lowercase, is "coap" or "coaps", then fail 2667 this algorithm. 2669 4. If /url/ has a component, then fail this algorithm. 2671 5. If the component of /url/ does not represent the request's 2672 destination IP address as an IP-literal or IPv4address, include a 2673 Uri-Host Option and let that option's value be the value of the 2674 component of /url/, converted to ASCII lowercase, and then 2675 converting all percent-encodings ("%" followed by two hexadecimal 2676 digits) to the corresponding characters. 2678 NOTE: In the usual case where the request's destination IP 2679 address is derived from the host part, this ensures that a Uri- 2680 Host Option is only used for a component of the form reg- 2681 name. 2683 6. If /url/ has a component, then let /port/ be that 2684 component's value interpreted as a decimal integer; otherwise, 2685 let /port/ be the default port for the scheme. 2687 7. If /port/ does not equal the request's destination UDP port, 2688 include a Uri-Port Option and let that option's value be /port/. 2690 8. If the value of the component of /url/ is empty or 2691 consists of a single slash character (U+002F SOLIDUS "/"), then 2692 move to the next step. 2694 Otherwise, for each segment in the component, include a 2695 Uri-Path Option and let that option's value be the segment (not 2696 including the delimiting slash characters) after converting all 2697 percent-encodings ("%" followed by two hexadecimal digits) to the 2698 corresponding characters. 2700 9. If /url/ has a component, then, for each argument in the 2701 component, include a Uri-Query Option and let that 2702 option's value be the argument (not including the question mark 2703 and the delimiting ampersand characters) after converting all 2704 percent-encodings to the corresponding characters. 2706 Note that these rules completely resolve any percent-encoding. 2708 6.5. Composing URIs from Options 2710 The steps to construct a URI from a request's options are as follows. 2711 These steps either result in a URI, or they fail. In these steps, 2712 percent-encoding a character means replacing each of its (UTF-8 2713 encoded) bytes by a "%" character followed by two hexadecimal digits 2714 representing the byte, where the digits A-F are in upper case (as 2715 defined in [RFC3986] Section 2.1; to reduce variability, the 2716 hexadecimal notation for percent-encoding in CoAP URIs MUST use 2717 uppercase letters). The definitions of "unreserved" and "sub-delims" 2718 are adopted from [RFC3986]. 2720 1. If the request is secured using DTLS, let /url/ be the string 2721 "coaps://". Otherwise, let /url/ be the string "coap://". 2723 2. If the request includes a Uri-Host Option, let /host/ be that 2724 option's value, where any non-ASCII characters are replaced by 2725 their corresponding percent-encoding. If /host/ is not a valid 2726 reg-name or IP-literal or IPv4address, fail the algorithm. If 2727 the request does not include a Uri-Host Option, let /host/ be 2728 the IP-literal (making use of the conventions of [RFC5952]) or 2729 IPv4address representing the request's destination IP address. 2731 3. Append /host/ to /url/. 2733 4. If the request includes a Uri-Port Option, let /port/ be that 2734 option's value. Otherwise, let /port/ be the request's 2735 destination UDP port. 2737 5. If /port/ is not the default port for the scheme, then append a 2738 single U+003A COLON character (:) followed by the decimal 2739 representation of /port/ to /url/. 2741 6. Let /resource name/ be the empty string. For each Uri-Path 2742 Option in the request, append a single character U+002F SOLIDUS 2743 (/) followed by the option's value to /resource name/, after 2744 converting any character that is not either in the "unreserved" 2745 set, "sub-delims" set, a U+003A COLON (:) or U+0040 COMMERCIAL 2746 AT (@) character, to its percent-encoded form. 2748 7. If /resource name/ is the empty string, set it to a single 2749 character U+002F SOLIDUS (/). 2751 8. For each Uri-Query Option in the request, append a single 2752 character U+003F QUESTION MARK (?) (first option) or U+0026 2753 AMPERSAND (&) (subsequent options) followed by the option's 2754 value to /resource name/, after converting any character that is 2755 not either in the "unreserved" set, "sub-delims" set (except 2756 U+0026 AMPERSAND (&)), a U+003A COLON (:), U+0040 COMMERCIAL AT 2757 (@), U+002F SOLIDUS (/) or U+003F QUESTION MARK (?) character, 2758 to its percent-encoded form. 2760 9. Append /resource name/ to /url/. 2762 10. Return /url/. 2764 Note that these steps have been designed to lead to a URI in normal 2765 form (see Section 6.3). 2767 7. Discovery 2769 7.1. Service Discovery 2771 A server is discovered by a client by the client knowing or learning 2772 a URI that references a resource in the namespace of the server. 2773 Alternatively, clients can use Multicast CoAP (see Section 8) and the 2774 "All CoAP Nodes" multicast address to find CoAP servers. 2776 Unless the port subcomponent in a "coap" or "coaps" URI indicates the 2777 UDP port at which the CoAP server is located, the server is assumed 2778 to be reachable at the default port. 2780 The CoAP default port number 5683 MUST be supported by a server that 2781 offers resources for resource discovery (see Section 7.2 below) and 2782 SHOULD be supported for providing access to other resources. The 2783 default port number [IANA_TBD_PORT] for DTLS-secured CoAP MAY be 2784 supported by a server for resource discovery and for providing access 2785 to other resources. In addition other endpoints may be hosted at 2786 other ports, e.g. in the dynamic port space. 2788 Implementation Note: When a CoAP server is hosted by a 6LoWPAN node, 2789 header compression efficiency is improved when it also supports a 2790 port number in the 61616-61631 compressed UDP port space defined 2791 in [RFC4944] (note that, as its UDP port differs from the default 2792 port, it is a different endpoint from the server at the default 2793 port). 2795 7.2. Resource Discovery 2797 The discovery of resources offered by a CoAP endpoint is extremely 2798 important in machine-to-machine applications where there are no 2799 humans in the loop and static interfaces result in fragility. A CoAP 2800 endpoint SHOULD support the CoRE Link Format of discoverable 2801 resources as described in [RFC6690]. It is up to the server which 2802 resources are made discoverable (if any). 2804 7.2.1. 'ct' Attribute 2806 This section defines a new Web Linking [RFC5988] attribute for use 2807 with [RFC6690]. The Content-Format code "ct" attribute provides a 2808 hint about the Content-Formats this resource returns. Note that this 2809 is only a hint, and does not override the Content-Format Option of a 2810 CoAP response obtained by actually requesting the representation of 2811 the resource. The value is in the CoAP identifier code format as a 2812 decimal ASCII integer and MUST be in the range of 0-65535 (16-bit 2813 unsigned integer). For example application/xml would be indicated as 2814 "ct=41". If no Content-Format code attribute is present then nothing 2815 about the type can be assumed. The Content-Format code attribute MAY 2816 include a space-separated sequence of Content-Format codes, 2817 indicating that multiple content-formats are available. The syntax 2818 of the attribute value is summarized in the production ct-value in 2819 Figure 12, where cardinal, SP and DQUOTE are defined as in [RFC6690]. 2821 ct-value = cardinal 2822 / DQUOTE cardinal *( 1*SP cardinal ) DQUOTE 2824 Figure 12 2826 8. Multicast CoAP 2828 CoAP supports making requests to a IP multicast group. This is 2829 defined by a series of deltas to Unicast CoAP. 2831 CoAP endpoints that offer services that they want other endpoints to 2832 be able to find using multicast service discovery, join one or more 2833 of the appropriate all-CoAP-nodes multicast addresses (Section 12.8) 2834 and listen on the default CoAP port. Note that an endpoint might 2835 receive multicast requests on other multicast addresses, including 2836 the all-nodes IPv6 address (or via broadcast on IPv4); an endpoint 2837 MUST therefore be prepared to receive such messages but MAY ignore 2838 them if multicast service discovery is not desired. 2840 8.1. Messaging Layer 2842 A multicast request is characterized by being transported in a CoAP 2843 message that is addressed to an IP multicast address instead of a 2844 CoAP endpoint. Such multicast requests MUST be Non-confirmable. 2846 A server SHOULD be aware that a request arrived via multicast, e.g. 2847 by making use of modern APIs such as IPV6_RECVPKTINFO [RFC3542], if 2848 available. 2850 When a server is aware that a request arrived via multicast, it MUST 2851 NOT return a RST in reply to NON. If it is not aware, it MAY return 2852 a RST in reply to NON as usual. Because such a Reset message will 2853 look identical to an RST for a unicast message from the sender, the 2854 sender MUST avoid using a Message ID that is also still active from 2855 this endpoint with any unicast endpoint that might receive the 2856 multicast message. 2858 8.2. Request/Response Layer 2860 When a server is aware that a request arrived via multicast, the 2861 server MAY always pretend it did not receive the request, in 2862 particular if it doesn't have anything useful to respond (e.g., if it 2863 only has an empty payload or an error response). The decision for 2864 this may depend on the application. (For example, in [RFC6690] query 2865 filtering, a server should not respond to a multicast request if the 2866 filter does not match.) 2868 If a server does decide to respond to a multicast request, it should 2869 not respond immediately. Instead, it should pick a duration for the 2870 period of time during which it intends to respond. For purposes of 2871 this exposition, we call the length of this period the Leisure. The 2872 specific value of this Leisure may depend on the application, or MAY 2873 be derived as described below. The server SHOULD then pick a random 2874 point of time within the chosen Leisure period to send back the 2875 unicast response to the multicast request. If further responses need 2876 to be sent based on the same multicast address membership, a new 2877 leisure period starts at the earliest after the previous one 2878 finishes. 2880 To compute a value for Leisure, the server should have a group size 2881 estimate G, a target data transfer rate R (which both should be 2882 chosen conservatively) and an estimated response size S; a rough 2883 lower bound for Leisure can then be computed as 2884 lb_Leisure = S * G / R 2886 E.g., for a multicast request with link-local scope on an 2.4 GHz 2887 IEEE 802.15.4 (6LoWPAN) network, G could be (relatively 2888 conservatively) set to 100, S to 100 bytes, and the target rate to a 2889 conservative 8 kbit/s = 1 kB/s. The resulting lower bound for the 2890 Leisure is 10 seconds. 2892 If a CoAP endpoint does not have suitable data to compute a value for 2893 Leisure, it MAY resort to DEFAULT_LEISURE. 2895 When matching a response to a multicast request, only the token MUST 2896 match; the source endpoint of the response does not need to (and will 2897 not) be the same as the destination endpoint of the original request. 2899 For the purposes of interpreting the Location-* options and any links 2900 embedded in the representation and, the request URI (base URI) 2901 relative to which the response is interpreted, is formed by replacing 2902 the multicast address in the Host component of the original request 2903 URI by the literal IP address of the endpoint actually responding. 2905 8.2.1. Caching 2907 When a client makes a multicast request, it always makes a new 2908 request to the multicast group (since there may be new group members 2909 that joined meanwhile or ones that did not get the previous request). 2910 It MAY update the cache with the received responses. Then it uses 2911 both cached-still-fresh and 'new' responses as the result of the 2912 request. 2914 A response received in reply to a GET request to a multicast group 2915 MAY be used to satisfy a subsequent request on the related unicast 2916 request URI. The unicast request URI is obtained by replacing the 2917 authority part of the request URI with the transport layer source 2918 address of the response message. 2920 A cache MAY revalidate a response by making a GET request on the 2921 related unicast request URI. 2923 A GET request to a multicast group MUST NOT contain an ETag option. 2924 A mechanism to suppress responses the client already has is left for 2925 further study. 2927 8.2.2. Proxying 2929 When a forward-proxy receives a request with a Proxy-Uri or URI 2930 constructed from Proxy-Scheme that indicates a multicast address, the 2931 proxy obtains a set of responses as described above and sends all 2932 responses (both cached-still-fresh and new) back to the original 2933 client. 2935 This specification does not provide a way to indicate the unicast- 2936 modified request URI (base URI) in responses thus forwarded. A 2937 proposal to address this can be found in section 3 of 2938 [I-D.bormann-coap-misc]. 2940 9. Securing CoAP 2942 This section defines the DTLS binding for CoAP. 2944 During the provisioning phase, a CoAP device is provided with the 2945 security information that it needs, including keying materials and 2946 access control lists. This specification defines provisioning for 2947 the RawPublicKey mode in Section 9.1.3.2.1. At the end of the 2948 provisioning phase, the device will be in one of four security modes 2949 with the following information for the given mode. The NoSec and 2950 RawPublicKey modes are mandatory to implement for this specification. 2952 NoSec: There is no protocol level security (DTLS is disabled). 2953 Alternative techniques to provide lower layer security SHOULD be 2954 used when appropriate. The use of IPsec is discussed in 2955 [I-D.bormann-core-ipsec-for-coap]. 2957 PreSharedKey: DTLS is enabled and there is a list of pre-shared keys 2958 [RFC4279] and each key includes a list of which nodes it can be 2959 used to communicate with as described in Section 9.1.3.1. At the 2960 extreme there may be one key for each node this CoAP node needs to 2961 communicate with (1:1 node/key ratio). 2963 RawPublicKey: DTLS is enabled and the device has an asymmetric key 2964 pair without a certificate (a raw public key) that is validated 2965 using an out-of-band mechanism [I-D.ietf-tls-oob-pubkey] as 2966 described in Section 9.1.3.2. The device also has an identity 2967 calculated from the public key and a list of identities of the 2968 nodes it can communicate with. 2970 Certificate: DTLS is enabled and the device has an asymmetric key 2971 pair with an X.509 certificate [RFC5280] that binds it to its 2972 Authority Name and is signed by some common trust root as 2973 described in Section 9.1.3.3. The device also has a list of root 2974 trust anchors that can be used for validating a certificate. 2976 In the "NoSec" mode, the system simply sends the packets over normal 2977 UDP over IP and is indicated by the "coap" scheme and the CoAP 2978 default port. The system is secured only by keeping attackers from 2979 being able to send or receive packets from the network with the CoAP 2980 nodes; see Section 11.5 for an additional complication with this 2981 approach. 2983 The other three security modes are achieved using DTLS and are 2984 indicated by the "coaps" scheme and DTLS-secured CoAP default port. 2985 The result is a security association that can be used to authenticate 2986 (within the limits of the security model) and, based on this 2987 authentication, authorize the communication partner. CoAP itself 2988 does not provide protocol primitives for authentication or 2989 authorization; where this is required, it can either be provided by 2990 communication security (i.e., IPsec or DTLS) or by object security 2991 (within the payload). Devices that require authorization for certain 2992 operations are expected to require one of these two forms of 2993 security. Necessarily, where an intermediary is involved, 2994 communication security only works when that intermediary is part of 2995 the trust relationships; CoAP does not provide a way to forward 2996 different levels of authorization that clients may have with an 2997 intermediary to further intermediaries or origin servers -- it 2998 therefore may be required to perform all authorization at the first 2999 intermediary. 3001 9.1. DTLS-secured CoAP 3003 Just as HTTP is secured using Transport Layer Security (TLS) over 3004 TCP, CoAP is secured using Datagram TLS (DTLS) [RFC6347] over UDP 3005 (see Figure 13). This section defines the CoAP binding to DTLS, 3006 along with the minimal mandatory-to-implement configurations 3007 appropriate for constrained environments. The binding is defined by 3008 a series of deltas to Unicast CoAP. DTLS is in practice TLS with 3009 added features to deal with the unreliable nature of the UDP 3010 transport. 3012 +----------------------+ 3013 | Application | 3014 +----------------------+ 3015 +----------------------+ 3016 | Requests/Responses | 3017 |----------------------| CoAP 3018 | Messages | 3019 +----------------------+ 3020 +----------------------+ 3021 | DTLS | 3022 +----------------------+ 3023 +----------------------+ 3024 | UDP | 3025 +----------------------+ 3027 Figure 13: Abstract layering of DTLS-secured CoAP 3029 In some constrained nodes (limited flash and/or RAM) and networks 3030 (limited bandwidth or high scalability requirements), and depending 3031 on the specific cipher suites in use, all modes of DTLS may not be 3032 applicable. Some DTLS cipher suites can add significant 3033 implementation complexity as well as some initial handshake overhead 3034 needed when setting up the security association. Once the initial 3035 handshake is completed, DTLS adds a limited per-datagram overhead of 3036 approximately 13 bytes, not including any initialization vectors/ 3037 nonces (e.g., 8 bytes with TLS_PSK_WITH_AES_128_CCM_8 [RFC6655]), 3038 integrity check values (e.g., 8 bytes with TLS_PSK_WITH_AES_128_CCM_8 3039 [RFC6655]) and padding required by the cipher suite. Whether and 3040 which mode of using DTLS is applicable for a CoAP-based application 3041 should be carefully weighed considering the specific cipher suites 3042 that may be applicable, and whether the session maintenance makes it 3043 compatible with application flows and sufficient resources are 3044 available on the constrained nodes and for the added network 3045 overhead. (For some modes of using DTLS, this specification 3046 identifies a mandatory to implement cipher suite. This is an 3047 implementation requirement to maximize interoperability in those 3048 cases where these cipher suites are indeed appropriate. The specific 3049 security policies of an application may determine the actual (set of) 3050 cipher suites that can be used.) DTLS is not applicable to group 3051 keying (multicast communication); however, it may be a component in a 3052 future group key management protocol. 3054 9.1.1. Messaging Layer 3056 The endpoint acting as the CoAP client should also act as the DTLS 3057 client. It should initiate a session to the server on the 3058 appropriate port. When the DTLS handshake has finished, the client 3059 may initiate the first CoAP request. All CoAP messages MUST be sent 3060 as DTLS "application data". 3062 The following rules are added for matching an ACK or RST to a CON 3063 message or a RST to a NON message: The DTLS session MUST be the same 3064 and the epoch MUST be the same. 3066 A message is the same when it is sent within the same DTLS session 3067 and same epoch and has the same Message ID. 3069 Note: When a Confirmable message is retransmitted, a new DTLS 3070 sequence_number is used for each attempt, even though the CoAP 3071 Message ID stays the same. So a recipient still has to perform 3072 deduplication as described in Section 4.5. Retransmissions MUST NOT 3073 be performed across epochs. 3075 DTLS connections in RawPublicKey and Certificate mode are set up 3076 using mutual authentication so they can remain up and be reused for 3077 future message exchanges in either direction. Devices can close a 3078 DTLS connection when they need to recover resources but in general 3079 they should keep the connection up for as long as possible. Closing 3080 the DTLS connection after every CoAP message exchange is very 3081 inefficient. 3083 9.1.2. Request/Response Layer 3085 The following rules are added for matching a response to a request: 3086 The DTLS session MUST be the same and the epoch MUST be the same. 3088 9.1.3. Endpoint Identity 3090 Devices SHOULD support the Server Name Indication (SNI) to indicate 3091 their Authority Name in the SNI HostName field as defined in Section 3092 3 of [RFC6066]. This is needed so that when a host that acts as a 3093 virtual server for multiple Authorities receives a new DTLS 3094 connection, it knows which keys to use for the DTLS session. 3096 9.1.3.1. Pre-Shared Keys 3098 When forming a connection to a new node, the system selects an 3099 appropriate key based on which nodes it is trying to reach and then 3100 forms a DTLS session using a PSK (Pre-Shared Key) mode of DTLS. 3101 Implementations in these modes MUST support the mandatory to 3102 implement cipher suite TLS_PSK_WITH_AES_128_CCM_8 as specified in 3103 [RFC6655]. 3105 The security considerations of [RFC4279] (Section 7) apply. In 3106 particular, applications should carefully weigh whether they need 3107 Perfect Forward Secrecy (PFS) or not and select an appropriate cipher 3108 suite (7.1). The entropy of the PSK must be sufficient to mitigate 3109 against brute-force and (where the PSK is not chosen randomly but by 3110 a human) dictionary attacks (7.2). The cleartext communication of 3111 client identities may leak data or compromise privacy (7.3). 3113 9.1.3.2. Raw Public Key Certificates 3115 In this mode the device has an asymmetric key pair but without an 3116 X.509 certificate (called a raw public key). A device MAY be 3117 configured with multiple raw public keys. The type and length of the 3118 raw public key depends on the cipher suite used. Implementations in 3119 RawPublicKey mode MUST support the mandatory to implement cipher 3120 suite TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 as specified in 3121 [I-D.mcgrew-tls-aes-ccm-ecc], [RFC5246], [RFC4492]. The mechanism 3122 for using raw public keys with TLS is specified in 3123 [I-D.ietf-tls-oob-pubkey]. 3125 9.1.3.2.1. Provisioning 3127 The RawPublicKey mode was designed to be easily provisioned in M2M 3128 deployments. It is assumed that each device has an appropriate 3129 asymmetric public key pair installed. An identifier is calculated 3130 from the public key as described in Section 2 of 3131 [I-D.farrell-decade-ni]. All implementations that support checking 3132 RawPublicKey identities MUST support at least the sha-256-120 mode 3133 (SHA-256 truncated to 120 bits). Implementations SHOULD support also 3134 longer length identifiers and MAY support shorter lengths. Note that 3135 the shorter lengths provide less security against attacks and their 3136 use is NOT RECOMMENDED. 3138 Depending on how identifiers are given to the system that verifies 3139 them, support for URI, binary, and/or human-speakable format 3140 [I-D.farrell-decade-ni] needs to be implemented. All implementations 3141 SHOULD support the binary mode and implementations that have a user 3142 interface SHOULD also support the human-speakable format. 3144 During provisioning, the identifier of each node is collected, for 3145 example by reading a barcode on the outside of the device or by 3146 obtaining a pre-compiled list of the identifiers. These identifiers 3147 are then installed in the corresponding endpoint, for example an M2M 3148 data collection server. The identifier is used for two purposes, to 3149 associate the endpoint with further device information and to perform 3150 access control. During provisioning, an access control list of 3151 identifiers the device may start DTLS sessions with SHOULD also be 3152 installed. 3154 9.1.3.3. X.509 Certificates 3156 Implementations in Certificate Mode MUST support the mandatory to 3157 implement cipher suite TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 as 3158 specified in [RFC5246]. 3160 The Authority Name in the certificate is the name that would be used 3161 in the Host part of a CoAP URI. It is worth noting that this would 3162 typically not be either an IP address or DNS name built in the usual 3163 way but would instead be built out of a long term unique identifier 3164 for the device such as the EUI-64 [EUI64]. The discovery process 3165 used in the system would build up the mapping between IP addresses of 3166 the given devices and the Authority Name for each device. Some 3167 devices could have more than one Authority and would need more than a 3168 single certificate. 3170 When a new connection is formed, the certificate from the remote 3171 device needs to be verified. If the CoAP node has a source of 3172 absolute time, then the node SHOULD check that the validity dates of 3173 the certificate are within range. The certificate MUST also be 3174 signed by an appropriate chain of trust. If the certificate contains 3175 a SubjectAltName, then the Authority Name MUST match at least one of 3176 the authority names of any CoAP URI found in a field of URI type in 3177 the SubjectAltName set. If there is no SubjectAltName in the 3178 certificate, then the Authoritative Name must match the CN found in 3179 the certificate using the matching rules defined in [RFC2818] with 3180 the exception that certificates with wildcards are not allowed. 3182 If the system has a shared key in addition to the certificate, then a 3183 cipher suite that includes the shared key such as 3184 TLS_RSA_PSK_WITH_AES_128_CBC_SHA [RFC4279] SHOULD be used. 3186 10. Cross-Protocol Proxying between CoAP and HTTP 3188 CoAP supports a limited subset of HTTP functionality, and thus cross- 3189 protocol proxying to HTTP is straightforward. There might be several 3190 reasons for proxying between CoAP and HTTP, for example when 3191 designing a web interface for use over either protocol or when 3192 realizing a CoAP-HTTP proxy. Likewise, CoAP could equally be proxied 3193 to other protocols such as XMPP [RFC6120] or SIP [RFC3264]; the 3194 definition of these mechanisms is out of scope of this specification. 3196 There are two possible directions to access a resource via a forward- 3197 proxy: 3199 CoAP-HTTP Proxying: Enables CoAP clients to access resources on HTTP 3200 servers through an intermediary. This is initiated by including 3201 the Proxy-Uri or Proxy-Scheme Option with an "http" or "https" URI 3202 in a CoAP request to a CoAP-HTTP proxy. 3204 HTTP-CoAP Proxying: Enables HTTP clients to access resources on CoAP 3205 servers through an intermediary. This is initiated by specifying 3206 a "coap" or "coaps" URI in the Request-Line of an HTTP request to 3207 an HTTP-CoAP proxy. 3209 Either way, only the Request/Response model of CoAP is mapped to 3210 HTTP. The underlying model of Confirmable or Non-confirmable 3211 messages, etc., is invisible and MUST have no effect on a proxy 3212 function. The following sections describe the handling of requests 3213 to a forward-proxy. Reverse proxies are not specified as the proxy 3214 function is transparent to the client with the proxy acting as if it 3215 was the origin server. However, similar considerations apply to 3216 reverse-proxies as to forward-proxies, and there generally will be an 3217 expectation that reverse-proxies operate in a similar way forward- 3218 proxies would. As an implementation note, HTTP client libraries may 3219 make it hard to operate an HTTP-CoAP forward proxy by not providing a 3220 way to put a CoAP URI on the HTTP Request-Line; reverse-proxying may 3221 therefore lead to wider applicability of a proxy. A separate 3222 specification may define a convention for URIs operating such a HTTP- 3223 CoAP reverse proxy [I-D.bormann-core-cross-reverse-convention]. 3225 10.1. CoAP-HTTP Proxying 3227 If a request contains a Proxy-Uri or Proxy-Scheme Option with an 3228 'http' or 'https' URI [RFC2616], then the receiving CoAP endpoint 3229 (called "the proxy" henceforth) is requested to perform the operation 3230 specified by the request method on the indicated HTTP resource and 3231 return the result to the client. 3233 This section specifies for any CoAP request the CoAP response that 3234 the proxy should return to the client. How the proxy actually 3235 satisfies the request is an implementation detail, although the 3236 typical case is expected to be the proxy translating and forwarding 3237 the request to an HTTP origin server. 3239 Since HTTP and CoAP share the basic set of request methods, 3240 performing a CoAP request on an HTTP resource is not so different 3241 from performing it on a CoAP resource. The meanings of the 3242 individual CoAP methods when performed on HTTP resources are 3243 explained in the subsections of this section. 3245 If the proxy is unable or unwilling to service a request with an HTTP 3246 URI, a 5.05 (Proxying Not Supported) response is returned to the 3247 client. If the proxy services the request by interacting with a 3248 third party (such as the HTTP origin server) and is unable to obtain 3249 a result within a reasonable time frame, a 5.04 (Gateway Timeout) 3250 response is returned; if a result can be obtained but is not 3251 understood, a 5.02 (Bad Gateway) response is returned. 3253 10.1.1. GET 3255 The GET method requests the proxy to return a representation of the 3256 HTTP resource identified by the request URI. 3258 Upon success, a 2.05 (Content) response code SHOULD be returned. The 3259 payload of the response MUST be a representation of the target HTTP 3260 resource, and the Content-Format Option be set accordingly. The 3261 response MUST indicate a Max-Age value that is no greater than the 3262 remaining time the representation can be considered fresh. If the 3263 HTTP entity has an entity tag, the proxy SHOULD include an ETag 3264 Option in the response and process ETag Options in requests as 3265 described below. 3267 A client can influence the processing of a GET request by including 3268 the following option: 3270 Accept: The request MAY include an Accept Option, identifying the 3271 preferred response content-format. 3273 ETag: The request MAY include one or more ETag Options, identifying 3274 responses that the client has stored. This requests the proxy to 3275 send a 2.03 (Valid) response whenever it would send a 2.05 3276 (Content) response with an entity tag in the requested set 3277 otherwise. Note that CoAP ETags are always strong ETags in the 3278 HTTP sense; CoAP does not have the equivalent of HTTP weak ETags, 3279 and there is no good way to make use of these in a cross-proxy. 3281 10.1.2. PUT 3283 The PUT method requests the proxy to update or create the HTTP 3284 resource identified by the request URI with the enclosed 3285 representation. 3287 If a new resource is created at the request URI, a 2.01 (Created) 3288 response MUST be returned to the client. If an existing resource is 3289 modified, a 2.04 (Changed) response MUST be returned to indicate 3290 successful completion of the request. 3292 10.1.3. DELETE 3294 The DELETE method requests the proxy to delete the HTTP resource 3295 identified by the request URI at the HTTP origin server. 3297 A 2.02 (Deleted) response MUST be returned to client upon success or 3298 if the resource does not exist at the time of the request. 3300 10.1.4. POST 3302 The POST method requests the proxy to have the representation 3303 enclosed in the request be processed by the HTTP origin server. The 3304 actual function performed by the POST method is determined by the 3305 origin server and dependent on the resource identified by the request 3306 URI. 3308 If the action performed by the POST method does not result in a 3309 resource that can be identified by a URI, a 2.04 (Changed) response 3310 MUST be returned to the client. If a resource has been created on 3311 the origin server, a 2.01 (Created) response MUST be returned. 3313 10.2. HTTP-CoAP Proxying 3315 If an HTTP request contains a Request-URI with a 'coap' or 'coaps' 3316 URI, then the receiving HTTP endpoint (called "the proxy" henceforth) 3317 is requested to perform the operation specified by the request method 3318 on the indicated CoAP resource and return the result to the client. 3320 This section specifies for any HTTP request the HTTP response that 3321 the proxy should return to the client. Unless otherwise specified 3322 all the statements made are RECOMMENDED behavior; some highly 3323 constrained implementations may need to resort to shortcuts. How the 3324 proxy actually satisfies the request is an implementation detail, 3325 although the typical case is expected to be the proxy translating and 3326 forwarding the request to a CoAP origin server. The meanings of the 3327 individual HTTP methods when performed on CoAP resources are 3328 explained in the subsections of this section. 3330 If the proxy is unable or unwilling to service a request with a CoAP 3331 URI, a 501 (Not Implemented) response is returned to the client. If 3332 the proxy services the request by interacting with a third party 3333 (such as the CoAP origin server) and is unable to obtain a result 3334 within a reasonable time frame, a 504 (Gateway Timeout) response is 3335 returned; if a result can be obtained but is not understood, a 502 3336 (Bad Gateway) response is returned. 3338 10.2.1. OPTIONS and TRACE 3340 As the OPTIONS and TRACE methods are not supported in CoAP a 501 (Not 3341 Implemented) error MUST be returned to the client. 3343 10.2.2. GET 3345 The GET method requests the proxy to return a representation of the 3346 CoAP resource identified by the Request-URI. 3348 Upon success, a 200 (OK) response is returned. The payload of the 3349 response MUST be a representation of the target CoAP resource, and 3350 the Content-Type and Content-Encoding header fields be set 3351 accordingly. The response MUST indicate a max-age directive that 3352 indicates a value no greater than the remaining time the 3353 representation can be considered fresh. If the CoAP response has an 3354 ETag option, the proxy should include an ETag header field in the 3355 response. 3357 A client can influence the processing of a GET request by including 3358 the following options: 3360 Accept: The most preferred Media-type of the HTTP Accept header 3361 field in a request is mapped to a CoAP Accept option. HTTP Accept 3362 Media-type ranges, parameters and extensions are not supported by 3363 the CoAP Accept option. If the proxy cannot send a response which 3364 is acceptable according to the combined Accept field value, then 3365 the proxy sends a 406 (not acceptable) response. The proxy MAY 3366 then retry the request with further Media-types from the HTTP 3367 Accept header field. 3369 Conditional GETs: Conditional HTTP GET requests that include an "If- 3370 Match" or "If-None-Match" request-header field can be mapped to a 3371 corresponding CoAP request. The "If-Modified-Since" and "If- 3372 Unmodified-Since" request-header fields are not directly supported 3373 by CoAP, but are implemented locally by a caching proxy. 3375 10.2.3. HEAD 3377 The HEAD method is identical to GET except that the server MUST NOT 3378 return a message-body in the response. 3380 Although there is no direct equivalent of HTTP's HEAD method in CoAP, 3381 an HTTP-CoAP proxy responds to HEAD requests for CoAP resources, and 3382 the HTTP headers are returned without a message-body. 3384 Implementation Note: An HTTP-CoAP proxy may want to try using a 3385 block-wise transfer [I-D.ietf-core-block] option to minimize the 3386 amount of data actually transferred, but needs to be prepared for 3387 the case that the origin server does not support block-wise 3388 transfers. 3390 10.2.4. POST 3392 The POST method requests the proxy to have the representation 3393 enclosed in the request be processed by the CoAP origin server. The 3394 actual function performed by the POST method is determined by the 3395 origin server and dependent on the resource identified by the request 3396 URI. 3398 If the action performed by the POST method does not result in a 3399 resource that can be identified by a URI, a 200 (OK) or 204 (No 3400 Content) response MUST be returned to the client. If a resource has 3401 been created on the origin server, a 201 (Created) response MUST be 3402 returned. 3404 If any of the Location-* Options are present in the CoAP response, a 3405 Location header field constructed from the values of these options is 3406 returned. 3408 10.2.5. PUT 3410 The PUT method requests the proxy to update or create the CoAP 3411 resource identified by the Request-URI with the enclosed 3412 representation. 3414 If a new resource is created at the Request-URI, a 201 (Created) 3415 response is returned to the client. If an existing resource is 3416 modified, either the 200 (OK) or 204 (No Content) response codes is 3417 sent to indicate successful completion of the request. 3419 10.2.6. DELETE 3421 The DELETE method requests the proxy to delete the CoAP resource 3422 identified by the Request-URI at the CoAP origin server. 3424 A successful response is 200 (OK) if the response includes an entity 3425 describing the status or 204 (No Content) if the action has been 3426 enacted but the response does not include an entity. 3428 10.2.7. CONNECT 3430 This method can not currently be satisfied by an HTTP-CoAP proxy 3431 function as TLS to DTLS tunneling has not yet been specified. For 3432 now, a 501 (Not Implemented) error is returned to the client. 3434 11. Security Considerations 3436 This section analyzes the possible threats to the protocol. It is 3437 meant to inform protocol and application developers about the 3438 security limitations of CoAP as described in this document. As CoAP 3439 realizes a subset of the features in HTTP/1.1, the security 3440 considerations in Section 15 of [RFC2616] are also pertinent to CoAP. 3441 This section concentrates on describing limitations specific to CoAP. 3443 11.1. Protocol Parsing, Processing URIs 3445 A network-facing application can exhibit vulnerabilities in its 3446 processing logic for incoming packets. Complex parsers are well- 3447 known as a likely source of such vulnerabilities, such as the ability 3448 to remotely crash a node, or even remotely execute arbitrary code on 3449 it. CoAP attempts to narrow the opportunities for introducing such 3450 vulnerabilities by reducing parser complexity, by giving the entire 3451 range of encodable values a meaning where possible, and by 3452 aggressively reducing complexity that is often caused by unnecessary 3453 choice between multiple representations that mean the same thing. 3454 Much of the URI processing has been moved to the clients, further 3455 reducing the opportunities for introducing vulnerabilities into the 3456 servers. Even so, the URI processing code in CoAP implementations is 3457 likely to be a large source of remaining vulnerabilities and should 3458 be implemented with special care. The most complex parser remaining 3459 could be the one for the CoRE Link Format, although this also has 3460 been designed with a goal of reduced implementation complexity 3461 [RFC6690]. (See also section 15.2 of [RFC2616].) 3463 11.2. Proxying and Caching 3465 As mentioned in 15.7 of [RFC2616], proxies are by their very nature 3466 men-in-the-middle, breaking any IPsec or DTLS protection that a 3467 direct CoAP message exchange might have. They are therefore 3468 interesting targets for breaking confidentiality or integrity of CoAP 3469 message exchanges. As noted in [RFC2616], they are also interesting 3470 targets for breaking availability. 3472 The threat to confidentiality and integrity of request/response data 3473 is amplified where proxies also cache. Note that CoAP does not 3474 define any of the cache-suppressing Cache-Control options that 3475 HTTP/1.1 provides to better protect sensitive data. 3477 For a caching implementation, any access control considerations that 3478 would apply to making the request that generated the cache entry also 3479 need to be applied to the value in the cache. This is relevant for 3480 clients that implement multiple security domains, as well as for 3481 proxies that may serve multiple clients. Also, a caching proxy MUST 3482 NOT make cached values available to requests that have lesser 3483 transport security properties than to which it would make available 3484 the process of forwarding the request in the first place. 3486 Unlike the "coap" scheme, responses to "coaps" identified requests 3487 are never "public" and thus MUST NOT be reused for shared caching 3488 unless the cache is able to make equivalent access control decisions 3489 to the ones that led to the cached entry. They can, however, be 3490 reused in a private cache if the message is cacheable by default in 3491 CoAP. 3493 Finally, a proxy that fans out Separate Responses (as opposed to 3494 Piggy-backed Responses) to multiple original requesters may provide 3495 additional amplification (see Section 11.3). 3497 11.3. Risk of amplification 3499 CoAP servers generally reply to a request packet with a response 3500 packet. This response packet may be significantly larger than the 3501 request packet. An attacker might use CoAP nodes to turn a small 3502 attack packet into a larger attack packet, an approach known as 3503 amplification. There is therefore a danger that CoAP nodes could 3504 become implicated in denial of service (DoS) attacks by using the 3505 amplifying properties of the protocol: An attacker that is attempting 3506 to overload a victim but is limited in the amount of traffic it can 3507 generate, can use amplification to generate a larger amount of 3508 traffic. 3510 This is particularly a problem in nodes that enable NoSec access, 3511 that are accessible from an attacker and can access potential victims 3512 (e.g. on the general Internet), as the UDP protocol provides no way 3513 to verify the source address given in the request packet. An 3514 attacker need only place the IP address of the victim in the source 3515 address of a suitable request packet to generate a larger packet 3516 directed at the victim. Such large amplification factors SHOULD NOT 3517 be done in the response if the request is not authenticated. 3519 As a mitigating factor, many constrained networks will only be able 3520 to generate a small amount of traffic, which may make CoAP nodes less 3521 attractive for this attack. However, the limited capacity of the 3522 constrained network makes the network itself a likely victim of an 3523 amplification attack. 3525 A CoAP server can reduce the amount of amplification it provides to 3526 an attacker by using slicing/blocking modes of CoAP 3528 [I-D.ietf-core-block] and offering large resource representations 3529 only in relatively small slices. E.g., for a 1000 byte resource, a 3530 10-byte request might result in an 80-byte response (with a 64-byte 3531 block) instead of a 1016-byte response, considerably reducing the 3532 amplification provided. 3534 CoAP also supports the use of multicast IP addresses in requests, an 3535 important requirement for M2M. Multicast CoAP requests may be the 3536 source of accidental or deliberate denial of service attacks, 3537 especially over constrained networks. This specification attempts to 3538 reduce the amplification effects of multicast requests by limiting 3539 when a response is returned. To limit the possibility of malicious 3540 use, CoAP servers SHOULD NOT accept multicast requests that can not 3541 be authenticated in some way, cryptographically or by some multicast 3542 boundary limiting the potential sources. If possible a CoAP server 3543 SHOULD limit the support for multicast requests to the specific 3544 resources where the feature is required. 3546 On some general purpose operating systems providing a Posix-style 3547 API, it is not straightforward to find out whether a packet received 3548 was addressed to a multicast address. While many implementations 3549 will know whether they have joined a multicast group, this creates a 3550 problem for packets addressed to multicast addresses of the form 3551 FF0x::1, which are received by every IPv6 node. Implementations 3552 SHOULD make use of modern APIs such as IPV6_RECVPKTINFO [RFC3542], if 3553 available, to make this determination. 3555 11.4. IP Address Spoofing Attacks 3557 Due to the lack of a handshake in UDP, a rogue endpoint which is free 3558 to read and write messages carried by the constrained network (i.e. 3559 NoSec or PreSharedKey deployments with nodes/key ratio > 1:1), may 3560 easily attack a single endpoint, a group of endpoints, as well as the 3561 whole network e.g. by: 3563 1. spoofing RST in response to a CON or NON message, thus making an 3564 endpoint "deaf"; or 3566 2. spoofing the entire response with forged payload/options (this 3567 has different levels of impact: from single response disruption, 3568 to much bolder attacks on the supporting infrastructure, e.g. 3569 poisoning proxy caches, or tricking validation / lookup 3570 interfaces in resource directories and, more generally, any 3571 component that stores global network state and uses CoAP as the 3572 messaging facility to handle state set/update's is a potential 3573 target.); or 3575 3. spoofing a multicast request for a target node which may result 3576 in both network congestion/collapse and victim DoS'ing / forced 3577 wakeup from sleeping; or 3579 4. spoofing observe messages, etc. 3581 In principle, spoofing can be detected by CoAP only in case CON 3582 semantics is used, because of unexpected ACK/RSTs coming from the 3583 deceived endpoint. But this imposes keeping track of the used 3584 Message IDs which is not always possible, and moreover detection 3585 becomes available usually after the damage is already done. This 3586 kind of attack can be prevented using security modes other than 3587 NoSec. 3589 11.5. Cross-Protocol Attacks 3591 The ability to incite a CoAP endpoint to send packets to a fake 3592 source address can be used not only for amplification, but also for 3593 cross-protocol attacks against a victim listening to UDP packets at a 3594 given address (IP address and port): 3596 o the attacker sends a message to a CoAP endpoint with the given 3597 address as the fake source address, 3599 o the CoAP endpoint replies with a message to the given source 3600 address, 3602 o the victim at the given address receives a UDP packet that it 3603 interprets according to the rules of a different protocol. 3605 This may be used to circumvent firewall rules that prevent direct 3606 communication from the attacker to the victim, but happen to allow 3607 communication from the CoAP endpoint (which may also host a valid 3608 role in the other protocol) to the victim. 3610 Also, CoAP endpoints may be the victim of a cross-protocol attack 3611 generated through an endpoint of another UDP-based protocol such as 3612 DNS. In both cases, attacks are possible if the security properties 3613 of the endpoints rely on checking IP addresses (and firewalling off 3614 direct attacks sent from outside using fake IP addresses). In 3615 general, because of their lack of context, UDP-based protocols are 3616 relatively easy targets for cross-protocol attacks. 3618 Finally, CoAP URIs transported by other means could be used to incite 3619 clients to send messages to endpoints of other protocols. 3621 One mitigation against cross-protocol attacks is strict checking of 3622 the syntax of packets received, combined with sufficient difference 3623 in syntax. As an example, it might help if it were difficult to 3624 incite a DNS server to send a DNS response that would pass the checks 3625 of a CoAP endpoint. Unfortunately, the first two bytes of a DNS 3626 reply are an ID that can be chosen by the attacker, which map into 3627 the interesting part of the CoAP header, and the next two bytes are 3628 then interpreted as CoAP's Message ID (i.e., any value is 3629 acceptable). The DNS count words may be interpreted as multiple 3630 instances of a (non-existent, but elective) CoAP option 0, or 3631 possibly as a Token. The echoed query finally may be manufactured by 3632 the attacker to achieve a desired effect on the CoAP endpoint; the 3633 response added by the server (if any) might then just be interpreted 3634 as added payload. 3636 1 1 1 1 1 1 3637 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 3638 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 3639 | ID | T, TKL, code 3640 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 3641 |QR| Opcode |AA|TC|RD|RA| Z | RCODE | Message ID 3642 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 3643 | QDCOUNT | (options 0) 3644 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 3645 | ANCOUNT | (options 0) 3646 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 3647 | NSCOUNT | (options 0) 3648 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 3649 | ARCOUNT | (options 0) 3650 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 3652 Figure 14: DNS Header vs. CoAP Message 3654 In general, for any pair of protocols, one of the protocols can very 3655 well have been designed in a way that enables an attacker to cause 3656 the generation of replies that look like messages of the other 3657 protocol. It is often much harder to ensure or prove the absence of 3658 viable attacks than to generate examples that may not yet completely 3659 enable an attack but might be further developed by more creative 3660 minds. Cross-protocol attacks can therefore only be completely 3661 mitigated if endpoints don't authorize actions desired by an attacker 3662 just based on trusting the source IP address of a packet. 3663 Conversely, a NoSec environment that completely relies on a firewall 3664 for CoAP security not only needs to firewall off the CoAP endpoints 3665 but also all other endpoints that might be incited to send UDP 3666 messages to CoAP endpoints using some other UDP-based protocol. 3668 In addition to the considerations above, the security considerations 3669 for DTLS with respect to cross-protocol attacks apply. E.g., if the 3670 same DTLS security association ("connection") is used to carry data 3671 of multiple protocols, DTLS no longer provides protection against 3672 cross-protocol attacks between these protocols. 3674 12. IANA Considerations 3676 12.1. CoAP Code Registry 3678 This document defines a registry for the values of the Code field in 3679 the CoAP header. The name of the registry is "CoAP Codes". 3681 All values are assigned by sub-registries according to the following 3682 ranges: 3684 0 Indicates an empty message (see Section 4.1). 3686 1-31 Indicates a request. Values in this range are assigned by 3687 the "CoAP Method Codes" sub-registry (see Section 12.1.1). 3689 32-63 Reserved 3691 64-191 Indicates a response. Values in this range are assigned by 3692 the "CoAP Response Codes" sub-registry (see 3693 Section 12.1.2). 3695 192-255 Reserved 3697 12.1.1. Method Codes 3699 The name of the sub-registry is "CoAP Method Codes". 3701 Each entry in the sub-registry must include the Method Code in the 3702 range 1-31, the name of the method, and a reference to the method's 3703 documentation. 3705 Initial entries in this sub-registry are as follows: 3707 +------+--------+-----------+ 3708 | Code | Name | Reference | 3709 +------+--------+-----------+ 3710 | 1 | GET | [RFCXXXX] | 3711 | 2 | POST | [RFCXXXX] | 3712 | 3 | PUT | [RFCXXXX] | 3713 | 4 | DELETE | [RFCXXXX] | 3714 +------+--------+-----------+ 3716 Table 4: CoAP Method Codes 3718 All other Method Codes are Unassigned. 3720 The IANA policy for future additions to this registry is "IETF Review 3721 or IESG approval" as described in [RFC5226]. 3723 The documentation of a method code should specify the semantics of a 3724 request with that code, including the following properties: 3726 o The response codes the method returns in the success case. 3728 o Whether the method is idempotent, safe, or both. 3730 12.1.2. Response Codes 3732 The name of the sub-registry is "CoAP Response Codes". 3734 Each entry in the sub-registry must include the Response Code in the 3735 range 64-191, a description of the Response Code, and a reference to 3736 the Response Code's documentation. 3738 Initial entries in this sub-registry are as follows: 3740 +------+---------------------------------+-----------+ 3741 | Code | Description | Reference | 3742 +------+---------------------------------+-----------+ 3743 | 65 | 2.01 Created | [RFCXXXX] | 3744 | 66 | 2.02 Deleted | [RFCXXXX] | 3745 | 67 | 2.03 Valid | [RFCXXXX] | 3746 | 68 | 2.04 Changed | [RFCXXXX] | 3747 | 69 | 2.05 Content | [RFCXXXX] | 3748 | 128 | 4.00 Bad Request | [RFCXXXX] | 3749 | 129 | 4.01 Unauthorized | [RFCXXXX] | 3750 | 130 | 4.02 Bad Option | [RFCXXXX] | 3751 | 131 | 4.03 Forbidden | [RFCXXXX] | 3752 | 132 | 4.04 Not Found | [RFCXXXX] | 3753 | 133 | 4.05 Method Not Allowed | [RFCXXXX] | 3754 | 134 | 4.06 Not Acceptable | [RFCXXXX] | 3755 | 140 | 4.12 Precondition Failed | [RFCXXXX] | 3756 | 141 | 4.13 Request Entity Too Large | [RFCXXXX] | 3757 | 143 | 4.15 Unsupported Content-Format | [RFCXXXX] | 3758 | 160 | 5.00 Internal Server Error | [RFCXXXX] | 3759 | 161 | 5.01 Not Implemented | [RFCXXXX] | 3760 | 162 | 5.02 Bad Gateway | [RFCXXXX] | 3761 | 163 | 5.03 Service Unavailable | [RFCXXXX] | 3762 | 164 | 5.04 Gateway Timeout | [RFCXXXX] | 3763 | 165 | 5.05 Proxying Not Supported | [RFCXXXX] | 3764 +------+---------------------------------+-----------+ 3765 Table 5: CoAP Response Codes 3767 The Response Codes 96-127 are Reserved for future use. All other 3768 Response Codes are Unassigned. 3770 The IANA policy for future additions to this registry is "IETF Review 3771 or IESG approval" as described in [RFC5226]. 3773 The documentation of a response code should specify the semantics of 3774 a response with that code, including the following properties: 3776 o The methods the response code applies to. 3778 o Whether payload is required, optional or not allowed. 3780 o The semantics of the payload. For example, the payload of a 2.05 3781 (Content) response is a representation of the target resource; the 3782 payload in an error response is a human-readable diagnostic 3783 payload. 3785 o The format of the payload. For example, the format in a 2.05 3786 (Content) response is indicated by the Content-Format Option; the 3787 format of the payload in an error response is always Net-Unicode 3788 text. 3790 o Whether the response is cacheable according to the freshness 3791 model. 3793 o Whether the response is validatable according to the validation 3794 model. 3796 o Whether the response causes a cache to mark responses stored for 3797 the request URI as not fresh. 3799 12.2. Option Number Registry 3801 This document defines a registry for the Option Numbers used in CoAP 3802 options. The name of the registry is "CoAP Option Numbers". 3804 Each entry in the registry must include the Option Number, the name 3805 of the option and a reference to the option's documentation. 3807 Initial entries in this registry are as follows: 3809 +--------+----------------+-----------+ 3810 | Number | Name | Reference | 3811 +--------+----------------+-----------+ 3812 | 0 | (Reserved) | | 3813 | 1 | If-Match | [RFCXXXX] | 3814 | 3 | Uri-Host | [RFCXXXX] | 3815 | 4 | ETag | [RFCXXXX] | 3816 | 5 | If-None-Match | [RFCXXXX] | 3817 | 7 | Uri-Port | [RFCXXXX] | 3818 | 8 | Location-Path | [RFCXXXX] | 3819 | 11 | Uri-Path | [RFCXXXX] | 3820 | 12 | Content-Format | [RFCXXXX] | 3821 | 14 | Max-Age | [RFCXXXX] | 3822 | 15 | Uri-Query | [RFCXXXX] | 3823 | 16 | Accept | [RFCXXXX] | 3824 | 20 | Location-Query | [RFCXXXX] | 3825 | 35 | Proxy-Uri | [RFCXXXX] | 3826 | 39 | Proxy-Scheme | [RFCXXXX] | 3827 | 128 | (Reserved) | [RFCXXXX] | 3828 | 132 | (Reserved) | [RFCXXXX] | 3829 | 136 | (Reserved) | [RFCXXXX] | 3830 | 140 | (Reserved) | [RFCXXXX] | 3831 +--------+----------------+-----------+ 3833 Table 6: CoAP Option Numbers 3835 The IANA policy for future additions to this registry is split into 3836 three tiers as follows. The range of 0..255 is reserved for options 3837 defined by the IETF (IETF Review or IESG approval). The range of 3838 256..2047 is reserved for commonly used options with public 3839 specifications (Specification Required). The range of 2048..64999 is 3840 for all other options including private or vendor specific ones, 3841 which undergo a Designated Expert review to help ensure that the 3842 option semantics are defined correctly. The option numbers between 3843 65000 and 65535 inclusive are reserved for experiments. They are not 3844 meant for vendor specific use of any kind and MUST NOT be used in 3845 operational deployments. 3847 +---------------+------------------------------+ 3848 | Option Number | Policy [RFC5226] | 3849 +---------------+------------------------------+ 3850 | 0..255 | IETF Review or IESG approval | 3851 | 256..2047 | Specification Required | 3852 | 2048..64999 | Designated Expert | 3853 | 65000..65535 | Reserved for experiments | 3854 +---------------+------------------------------+ 3856 The documentation of an Option Number should specify the semantics of 3857 an option with that number, including the following properties: 3859 o The meaning of the option in a request. 3861 o The meaning of the option in a response. 3863 o Whether the option is critical or elective, as determined by the 3864 Option Number. 3866 o Whether the option is Safe, and, if yes, whether it is part of the 3867 Cache-Key, as determined by the Option Number (see Section 5.4.2). 3869 o The format and length of the option's value. 3871 o Whether the option must occur at most once or whether it can occur 3872 multiple times. 3874 o The default value, if any. For a critical option with a default 3875 value, a discussion on how the default value enables processing by 3876 implementations not implementing the critical option 3877 (Section 5.4.4). 3879 12.3. Content-Format Registry 3881 Internet media types are identified by a string, such as 3882 "application/xml" [RFC2046]. In order to minimize the overhead of 3883 using these media types to indicate the format of payloads, this 3884 document defines a registry for a subset of Internet media types to 3885 be used in CoAP and assigns each, in combination with a content- 3886 coding, a numeric identifier. The name of the registry is "CoAP 3887 Content-Formats". 3889 Each entry in the registry must include the media type registered 3890 with IANA, the numeric identifier in the range 0-65535 to be used for 3891 that media type in CoAP, the content-coding associated with this 3892 identifier, and a reference to a document describing what a payload 3893 with that media type means semantically. 3895 CoAP does not include a separate way to convey content-encoding 3896 information with a request or response, and for that reason the 3897 content-encoding is also specified for each identifier (if any). If 3898 multiple content-encodings will be used with a media type, then a 3899 separate Content-Format identifier for each is to be registered. 3900 Similarly, other parameters related to an Internet media type, such 3901 as level, can be defined for a CoAP Content-Format entry. 3903 Initial entries in this registry are as follows: 3905 +--------------------+----------+-----+-----------------------------+ 3906 | Media type | Encoding | Id. | Reference | 3907 +--------------------+----------+-----+-----------------------------+ 3908 | text/plain; | - | 0 | [RFC2046][RFC3676][RFC5147] | 3909 | charset=utf-8 | | | | 3910 | application/ | - | 40 | [RFC6690] | 3911 | link-format | | | | 3912 | application/xml | - | 41 | [RFC3023] | 3913 | application/ | - | 42 | [RFC2045][RFC2046] | 3914 | octet-stream | | | | 3915 | application/exi | - | 47 | [EXIMIME] | 3916 | application/json | - | 50 | [RFC4627] | 3917 +--------------------+----------+-----+-----------------------------+ 3919 Table 7: CoAP Content-Formats 3921 The identifiers between 65000 and 65535 inclusive are reserved for 3922 experiments. They are not meant for vendor specific use of any kind 3923 and MUST NOT be used in operational deployments. The identifiers 3924 between 256 and 9999 are reserved for future use in IETF 3925 specifications (IETF review or IESG approval). All other identifiers 3926 are Unassigned. 3928 Because the name space of single-byte identifiers is so small, the 3929 IANA policy for future additions in the range 0-255 inclusive to the 3930 registry is "Expert Review" as described in [RFC5226]. The IANA 3931 policy for additions in the range 10000-64999 inclusive is "First 3932 Come First Served" as described in [RFC5226]. 3934 In machine to machine applications, it is not expected that generic 3935 Internet media types such as text/plain, application/xml or 3936 application/octet-stream are useful for real applications in the long 3937 term. It is recommended that M2M applications making use of CoAP 3938 will request new Internet media types from IANA indicating semantic 3939 information about how to create or parse a payload. For example, a 3940 Smart Energy application payload carried as XML might request a more 3941 specific type like application/se+xml or application/se-exi. 3943 12.4. URI Scheme Registration 3945 This document requests the registration of the Uniform Resource 3946 Identifier (URI) scheme "coap". The registration request complies 3947 with [RFC4395]. 3949 URI scheme name. 3950 coap 3952 Status. 3953 Permanent. 3955 URI scheme syntax. 3956 Defined in Section 6.1 of [RFCXXXX]. 3958 URI scheme semantics. 3959 The "coap" URI scheme provides a way to identify resources that 3960 are potentially accessible over the Constrained Application 3961 Protocol (CoAP). The resources can be located by contacting the 3962 governing CoAP server and operated on by sending CoAP requests to 3963 the server. This scheme can thus be compared to the "http" URI 3964 scheme [RFC2616]. See Section 6 of [RFCXXXX] for the details of 3965 operation. 3967 Encoding considerations. 3968 The scheme encoding conforms to the encoding rules established for 3969 URIs in [RFC3986], i.e. internationalized and reserved characters 3970 are expressed using UTF-8-based percent-encoding. 3972 Applications/protocols that use this URI scheme name. 3973 The scheme is used by CoAP endpoints to access CoAP resources. 3975 Interoperability considerations. 3976 None. 3978 Security considerations. 3979 See Section 11.1 of [RFCXXXX]. 3981 Contact. 3982 IETF Chair 3984 Author/Change controller. 3985 IESG 3987 References. 3988 [RFCXXXX] 3990 12.5. Secure URI Scheme Registration 3992 This document requests the registration of the Uniform Resource 3993 Identifier (URI) scheme "coaps". The registration request complies 3994 with [RFC4395]. 3996 URI scheme name. 3997 coaps 3999 Status. 4000 Permanent. 4002 URI scheme syntax. 4003 Defined in Section 6.2 of [RFCXXXX]. 4005 URI scheme semantics. 4006 The "coaps" URI scheme provides a way to identify resources that 4007 are potentially accessible over the Constrained Application 4008 Protocol (CoAP) using Datagram Transport Layer Security (DTLS) for 4009 transport security. The resources can be located by contacting 4010 the governing CoAP server and operated on by sending CoAP requests 4011 to the server. This scheme can thus be compared to the "https" 4012 URI scheme [RFC2616]. See Section 6 of [RFCXXXX] for the details 4013 of operation. 4015 Encoding considerations. 4016 The scheme encoding conforms to the encoding rules established for 4017 URIs in [RFC3986], i.e. internationalized and reserved characters 4018 are expressed using UTF-8-based percent-encoding. 4020 Applications/protocols that use this URI scheme name. 4021 The scheme is used by CoAP endpoints to access CoAP resources 4022 using DTLS. 4024 Interoperability considerations. 4025 None. 4027 Security considerations. 4028 See Section 11.1 of [RFCXXXX]. 4030 Contact. 4031 IETF Chair 4033 Author/Change controller. 4034 IESG 4036 References. 4037 [RFCXXXX] 4039 12.6. Service Name and Port Number Registration 4041 One of the functions of CoAP is resource discovery: a CoAP client can 4042 ask a CoAP server about the resources offered by it (see Section 7). 4043 To enable resource discovery just based on the knowledge of an IP 4044 address, the CoAP port for resource discovery needs to be 4045 standardized. 4047 IANA has assigned the port number 5683 and the service name "coap", 4048 in accordance with [RFC6335]. 4050 Besides unicast, CoAP can be used with both multicast and anycast. 4052 Service Name. 4053 coap 4055 Transport Protocol. 4056 UDP 4058 Assignee. 4059 IESG 4061 Contact. 4062 IETF Chair 4064 Description. 4065 Constrained Application Protocol (CoAP) 4067 Reference. 4068 [RFCXXXX] 4070 Port Number. 4071 5683 4073 12.7. Secure Service Name and Port Number Registration 4075 CoAP resource discovery may also be provided using the DTLS-secured 4076 CoAP "coaps" scheme. Thus the CoAP port for secure resource 4077 discovery needs to be standardized. 4079 This document requests the assignment of the port number 4080 [IANA_TBD_PORT] and the service name "coaps", in accordance with 4081 [RFC6335]. 4083 Besides unicast, DTLS-secured CoAP can be used with anycast. 4085 Service Name. 4086 coaps 4088 Transport Protocol. 4089 UDP 4091 Assignee. 4092 IESG 4094 Contact. 4095 IETF Chair 4097 Description. 4098 DTLS-secured CoAP 4100 Reference. 4101 [RFCXXXX] 4103 Port Number. 4104 [IANA_TBD_PORT] 4106 12.8. Multicast Address Registration 4108 Section 8, "Multicast CoAP", defines the use of multicast. This 4109 document requests the assignment of the following multicast addresses 4110 for use by CoAP nodes: 4112 IPv4 -- "All CoAP Nodes" address [TBD1], from the IPv4 Multicast 4113 Address Space Registry. As the address is used for discovery that 4114 may span beyond a single network, it should come from the 4115 Internetwork Control Block (224.0.1.x, RFC 5771). 4117 IPv6 -- "All CoAP Nodes" address [TBD2], from the IPv6 Multicast 4118 Address Space Registry, in the Variable Scope Multicast Addresses 4119 space (RFC3307). Note that there is a distinct multicast address 4120 for each scope that interested CoAP nodes should listen to; CoAP 4121 needs the Link-Local and Site-Local scopes only. The address 4122 should be of the form FF0x::nn, where nn is a single byte, to 4123 ensure good compression of the local-scope address with [RFC6282]. 4125 [The explanatory text to be removed upon allocation of the addresses, 4126 except for the note about the distinct multicast addresses.] 4128 13. Acknowledgements 4130 Brian Frank was a contributor to and co-author of previous drafts of 4131 this specification. 4133 Special thanks to Peter Bigot, Esko Dijk and Cullen Jennings for 4134 substantial contributions to the ideas and text in the document, 4135 along with countless detailed reviews and discussions. 4137 Thanks to Ed Beroset, Angelo P. Castellani, Gilbert Clark, Robert 4138 Cragie, Esko Dijk, Lisa Dussealt, Thomas Fossati, Tom Herbst, Richard 4139 Kelsey, Ari Keranen, Matthias Kovatsch, Salvatore Loreto, Kerry Lynn, 4140 Alexey Melnikov, Guido Moritz, Petri Mutka, Colin O'Flynn, Charles 4141 Palmer, Adriano Pezzuto, Robert Quattlebaum, Akbar Rahman, Eric 4142 Rescorla, David Ryan, Szymon Sasin, Michael Scharf, Dale Seed, Robby 4143 Simpson, Peter van der Stok, Michael Stuber, Linyi Tian, Gilman 4144 Tolle, Matthieu Vial and Alper Yegin for helpful comments and 4145 discussions that have shaped the document. 4147 Some of the text has been borrowed from the working documents of the 4148 IETF httpbis working group. 4150 14. References 4152 14.1. Normative References 4154 [I-D.farrell-decade-ni] 4155 Farrell, S., Kutscher, D., Dannewitz, C., Ohlman, B., 4156 Keraenen, A., and P. Hallam-Baker, "Naming Things with 4157 Hashes", draft-farrell-decade-ni-10 (work in progress), 4158 August 2012. 4160 [I-D.ietf-tls-oob-pubkey] 4161 Wouters, P., Tschofenig, H., Gilmore, J., Weiler, S., and 4162 T. Kivinen, "Out-of-Band Public Key Validation for 4163 Transport Layer Security (TLS)", 4164 draft-ietf-tls-oob-pubkey-07 (work in progress), 4165 February 2013. 4167 [RFC0768] Postel, J., "User Datagram Protocol", STD 6, RFC 768, 4168 August 1980. 4170 [RFC2045] Freed, N. and N. Borenstein, "Multipurpose Internet Mail 4171 Extensions (MIME) Part One: Format of Internet Message 4172 Bodies", RFC 2045, November 1996. 4174 [RFC2046] Freed, N. and N. Borenstein, "Multipurpose Internet Mail 4175 Extensions (MIME) Part Two: Media Types", RFC 2046, 4176 November 1996. 4178 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 4179 Requirement Levels", BCP 14, RFC 2119, March 1997. 4181 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 4182 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 4183 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 4185 [RFC3023] Murata, M., St. Laurent, S., and D. Kohn, "XML Media 4186 Types", RFC 3023, January 2001. 4188 [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 4189 10646", STD 63, RFC 3629, November 2003. 4191 [RFC3676] Gellens, R., "The Text/Plain Format and DelSp Parameters", 4192 RFC 3676, February 2004. 4194 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 4195 Resource Identifier (URI): Generic Syntax", STD 66, 4196 RFC 3986, January 2005. 4198 [RFC4279] Eronen, P. and H. Tschofenig, "Pre-Shared Key Ciphersuites 4199 for Transport Layer Security (TLS)", RFC 4279, 4200 December 2005. 4202 [RFC4395] Hansen, T., Hardie, T., and L. Masinter, "Guidelines and 4203 Registration Procedures for New URI Schemes", BCP 35, 4204 RFC 4395, February 2006. 4206 [RFC5147] Wilde, E. and M. Duerst, "URI Fragment Identifiers for the 4207 text/plain Media Type", RFC 5147, April 2008. 4209 [RFC5198] Klensin, J. and M. Padlipsky, "Unicode Format for Network 4210 Interchange", RFC 5198, March 2008. 4212 [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an 4213 IANA Considerations Section in RFCs", BCP 26, RFC 5226, 4214 May 2008. 4216 [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax 4217 Specifications: ABNF", STD 68, RFC 5234, January 2008. 4219 [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security 4220 (TLS) Protocol Version 1.2", RFC 5246, August 2008. 4222 [RFC5280] Cooper, D., Santesson, S., Farrell, S., Boeyen, S., 4223 Housley, R., and W. Polk, "Internet X.509 Public Key 4224 Infrastructure Certificate and Certificate Revocation List 4225 (CRL) Profile", RFC 5280, May 2008. 4227 [RFC5785] Nottingham, M. and E. Hammer-Lahav, "Defining Well-Known 4228 Uniform Resource Identifiers (URIs)", RFC 5785, 4229 April 2010. 4231 [RFC5952] Kawamura, S. and M. Kawashima, "A Recommendation for IPv6 4232 Address Text Representation", RFC 5952, August 2010. 4234 [RFC5988] Nottingham, M., "Web Linking", RFC 5988, October 2010. 4236 [RFC6066] Eastlake, D., "Transport Layer Security (TLS) Extensions: 4237 Extension Definitions", RFC 6066, January 2011. 4239 [RFC6347] Rescorla, E. and N. Modadugu, "Datagram Transport Layer 4240 Security Version 1.2", RFC 6347, January 2012. 4242 [RFC6690] Shelby, Z., "Constrained RESTful Environments (CoRE) Link 4243 Format", RFC 6690, August 2012. 4245 14.2. Informative References 4247 [EUI64] "GUIDELINES FOR 64-BIT GLOBAL IDENTIFIER (EUI-64) 4248 REGISTRATION AUTHORITY", April 2010, . 4251 [EXIMIME] "Efficient XML Interchange (EXI) Format 1.0", 4252 December 2009, . 4255 [I-D.allman-tcpm-rto-consider] 4256 Allman, M., "Retransmission Timeout Considerations", 4257 draft-allman-tcpm-rto-consider-01 (work in progress), 4258 May 2012. 4260 [I-D.bormann-coap-misc] 4261 Bormann, C. and K. Hartke, "Miscellaneous additions to 4262 CoAP", draft-bormann-coap-misc-23 (work in progress), 4263 March 2013. 4265 [I-D.bormann-core-cross-reverse-convention] 4266 Bormann, C., "A convention for URIs operating a HTTP-CoAP 4267 reverse proxy", 4268 draft-bormann-core-cross-reverse-convention-00 (work in 4269 progress), December 2012. 4271 [I-D.bormann-core-ipsec-for-coap] 4272 Bormann, C., "Using CoAP with IPsec", 4273 draft-bormann-core-ipsec-for-coap-00 (work in progress), 4274 December 2012. 4276 [I-D.ietf-core-block] 4277 Bormann, C. and Z. Shelby, "Blockwise transfers in CoAP", 4278 draft-ietf-core-block-10 (work in progress), October 2012. 4280 [I-D.ietf-core-observe] 4281 Hartke, K., "Observing Resources in CoAP", 4282 draft-ietf-core-observe-08 (work in progress), 4283 February 2013. 4285 [I-D.mcgrew-tls-aes-ccm-ecc] 4286 McGrew, D., Bailey, D., Campagna, M., and R. Dugal, "AES- 4287 CCM ECC Cipher Suites for TLS", 4288 draft-mcgrew-tls-aes-ccm-ecc-06 (work in progress), 4289 February 2013. 4291 [REST] Fielding, R., "Architectural Styles and the Design of 4292 Network-based Software Architectures", Ph.D. Dissertation, 4293 University of California, Irvine, 2000, . 4297 [RFC0793] Postel, J., "Transmission Control Protocol", STD 7, 4298 RFC 793, September 1981. 4300 [RFC2818] Rescorla, E., "HTTP Over TLS", RFC 2818, May 2000. 4302 [RFC3264] Rosenberg, J. and H. Schulzrinne, "An Offer/Answer Model 4303 with Session Description Protocol (SDP)", RFC 3264, 4304 June 2002. 4306 [RFC3542] Stevens, W., Thomas, M., Nordmark, E., and T. Jinmei, 4307 "Advanced Sockets Application Program Interface (API) for 4308 IPv6", RFC 3542, May 2003. 4310 [RFC4492] Blake-Wilson, S., Bolyard, N., Gupta, V., Hawk, C., and B. 4311 Moeller, "Elliptic Curve Cryptography (ECC) Cipher Suites 4312 for Transport Layer Security (TLS)", RFC 4492, May 2006. 4314 [RFC4627] Crockford, D., "The application/json Media Type for 4315 JavaScript Object Notation (JSON)", RFC 4627, July 2006. 4317 [RFC4944] Montenegro, G., Kushalnagar, N., Hui, J., and D. Culler, 4318 "Transmission of IPv6 Packets over IEEE 802.15.4 4319 Networks", RFC 4944, September 2007. 4321 [RFC5405] Eggert, L. and G. Fairhurst, "Unicast UDP Usage Guidelines 4322 for Application Designers", BCP 145, RFC 5405, 4323 November 2008. 4325 [RFC6120] Saint-Andre, P., "Extensible Messaging and Presence 4326 Protocol (XMPP): Core", RFC 6120, March 2011. 4328 [RFC6282] Hui, J. and P. Thubert, "Compression Format for IPv6 4329 Datagrams over IEEE 802.15.4-Based Networks", RFC 6282, 4330 September 2011. 4332 [RFC6335] Cotton, M., Eggert, L., Touch, J., Westerlund, M., and S. 4334 Cheshire, "Internet Assigned Numbers Authority (IANA) 4335 Procedures for the Management of the Service Name and 4336 Transport Protocol Port Number Registry", BCP 165, 4337 RFC 6335, August 2011. 4339 [RFC6655] McGrew, D. and D. Bailey, "AES-CCM Cipher Suites for 4340 Transport Layer Security (TLS)", RFC 6655, July 2012. 4342 Appendix A. Examples 4344 This section gives a number of short examples with message flows for 4345 GET requests. These examples demonstrate the basic operation, the 4346 operation in the presence of retransmissions, and multicast. 4348 Figure 15 shows a basic GET request causing a piggy-backed response: 4349 The client sends a Confirmable GET request for the resource 4350 coap://server/temperature to the server with a Message ID of 0x7d34. 4351 The request includes one Uri-Path Option (Delta 0 + 11 = 11, Length 4352 11, Value "temperature"); the Token is left empty. This request is a 4353 total of 16 bytes long. A 2.05 (Content) response is returned in the 4354 Acknowledgement message that acknowledges the Confirmable request, 4355 echoing both the Message ID 0x7d34 and the empty Token value. The 4356 response includes a Payload of "22.3 C" and is 11 bytes long. 4358 Client Server 4359 | | 4360 | | 4361 +----->| Header: GET (T=CON, Code=1, MID=0x7d34) 4362 | GET | Uri-Path: "temperature" 4363 | | 4364 | | 4365 |<-----+ Header: 2.05 Content (T=ACK, Code=69, MID=0x7d34) 4366 | 2.05 | Payload: "22.3 C" 4367 | | 4369 0 1 2 3 4370 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 4371 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4372 | 1 | 0 | 0 | GET=1 | MID=0x7d34 | 4373 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4374 | 11 | 11 | "temperature" (11 B) ... 4375 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4377 0 1 2 3 4378 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 4379 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4380 | 1 | 2 | 0 | 2.05=69 | MID=0x7d34 | 4381 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4382 |1 1 1 1 1 1 1 1| "22.3 C" (6 B) ... 4383 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4385 Figure 15: Confirmable request; piggy-backed response 4387 Figure 16 shows a similar example, but with the inclusion of an non- 4388 empty Token (Value 0x20) in the request and the response, increasing 4389 the sizes to 17 and 12 bytes, respectively. 4391 Client Server 4392 | | 4393 | | 4394 +----->| Header: GET (T=CON, Code=1, MID=0x7d35) 4395 | GET | Token: 0x20 4396 | | Uri-Path: "temperature" 4397 | | 4398 | | 4399 |<-----+ Header: 2.05 Content (T=ACK, Code=69, MID=0x7d35) 4400 | 2.05 | Token: 0x20 4401 | | Payload: "22.3 C" 4402 | | 4404 0 1 2 3 4405 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 4406 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4407 | 1 | 0 | 1 | GET=1 | MID=0x7d35 | 4408 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4409 | 0x20 | 4410 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4411 | 11 | 11 | "temperature" (11 B) ... 4412 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4414 0 1 2 3 4415 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 4416 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4417 | 1 | 2 | 1 | 2.05=69 | MID=0x7d35 | 4418 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4419 | 0x20 | 4420 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4421 |1 1 1 1 1 1 1 1| "22.3 C" (6 B) ... 4422 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4424 Figure 16: Confirmable request; piggy-backed response 4426 In Figure 17, the Confirmable GET request is lost. After ACK_TIMEOUT 4427 seconds, the client retransmits the request, resulting in a piggy- 4428 backed response as in the previous example. 4430 Client Server 4431 | | 4432 | | 4433 +----X | Header: GET (T=CON, Code=1, MID=0x7d36) 4434 | GET | Token: 0x31 4435 | | Uri-Path: "temperature" 4436 TIMEOUT | 4437 | | 4438 +----->| Header: GET (T=CON, Code=1, MID=0x7d36) 4439 | GET | Token: 0x31 4440 | | Uri-Path: "temperature" 4441 | | 4442 | | 4443 |<-----+ Header: 2.05 Content (T=ACK, Code=69, MID=0x7d36) 4444 | 2.05 | Token: 0x31 4445 | | Payload: "22.3 C" 4446 | | 4448 Figure 17: Confirmable request (retransmitted); piggy-backed response 4450 In Figure 18, the first Acknowledgement message from the server to 4451 the client is lost. After ACK_TIMEOUT seconds, the client 4452 retransmits the request. 4454 Client Server 4455 | | 4456 | | 4457 +----->| Header: GET (T=CON, Code=1, MID=0x7d37) 4458 | GET | Token: 0x42 4459 | | Uri-Path: "temperature" 4460 | | 4461 | | 4462 | X----+ Header: 2.05 Content (T=ACK, Code=69, MID=0x7d37) 4463 | 2.05 | Token: 0x42 4464 | | Payload: "22.3 C" 4465 TIMEOUT | 4466 | | 4467 +----->| Header: GET (T=CON, Code=1, MID=0x7d37) 4468 | GET | Token: 0x42 4469 | | Uri-Path: "temperature" 4470 | | 4471 | | 4472 |<-----+ Header: 2.05 Content (T=ACK, Code=69, MID=0x7d37) 4473 | 2.05 | Token: 0x42 4474 | | Payload: "22.3 C" 4475 | | 4477 Figure 18: Confirmable request; piggy-backed response (retransmitted) 4478 In Figure 19, the server acknowledges the Confirmable request and 4479 sends a 2.05 (Content) response separately in a Confirmable message. 4480 Note that the Acknowledgement message and the Confirmable response do 4481 not necessarily arrive in the same order as they were sent. The 4482 client acknowledges the Confirmable response. 4484 Client Server 4485 | | 4486 | | 4487 +----->| Header: GET (T=CON, Code=1, MID=0x7d38) 4488 | GET | Token: 0x53 4489 | | Uri-Path: "temperature" 4490 | | 4491 | | 4492 |<- - -+ Header: (T=ACK, Code=0, MID=0x7d38) 4493 | | 4494 | | 4495 |<-----+ Header: 2.05 Content (T=CON, Code=69, MID=0xad7b) 4496 | 2.05 | Token: 0x53 4497 | | Payload: "22.3 C" 4498 | | 4499 | | 4500 +- - ->| Header: (T=ACK, Code=0, MID=0xad7b) 4501 | | 4503 Figure 19: Confirmable request; separate response 4505 Figure 20 shows an example where the client loses its state (e.g., 4506 crashes and is rebooted) right after sending a Confirmable request, 4507 so the separate response arriving some time later comes unexpected. 4508 In this case, the client rejects the Confirmable response with a 4509 Reset message. Note that the unexpected ACK is silently ignored. 4511 Client Server 4512 | | 4513 | | 4514 +----->| Header: GET (T=CON, Code=1, MID=0x7d39) 4515 | GET | Token: 0x64 4516 | | Uri-Path: "temperature" 4517 CRASH | 4518 | | 4519 |<- - -+ Header: (T=ACK, Code=0, MID=0x7d39) 4520 | | 4521 | | 4522 |<-----+ Header: 2.05 Content (T=CON, Code=69, MID=0xad7c) 4523 | 2.05 | Token: 0x64 4524 | | Payload: "22.3 C" 4525 | | 4526 | | 4527 +- - ->| Header: (T=RST, Code=0, MID=0xad7c) 4528 | | 4530 Figure 20: Confirmable request; separate response (unexpected) 4532 Figure 21 shows a basic GET request where the request and the 4533 response are Non-confirmable, so both may be lost without notice. 4535 Client Server 4536 | | 4537 | | 4538 +----->| Header: GET (T=NON, Code=1, MID=0x7d40) 4539 | GET | Token: 0x75 4540 | | Uri-Path: "temperature" 4541 | | 4542 | | 4543 |<-----+ Header: 2.05 Content (T=NON, Code=69, MID=0xad7d) 4544 | 2.05 | Token: 0x75 4545 | | Payload: "22.3 C" 4546 | | 4548 Figure 21: Non-confirmable request; Non-confirmable response 4550 In Figure 22, the client sends a Non-confirmable GET request to a 4551 multicast address: all nodes in link-local scope. There are 3 4552 servers on the link: A, B and C. Servers A and B have a matching 4553 resource, therefore they send back a Non-confirmable 2.05 (Content) 4554 response. The response sent by B is lost. C does not have matching 4555 response, therefore it sends a Non-confirmable 4.04 (Not Found) 4556 response. 4558 Client ff02::1 A B C 4559 | | | | | 4560 | | | | | 4561 +------>| | | | Header: GET (T=NON, Code=1, MID=0x7d41) 4562 | GET | | | | Token: 0x86 4563 | | | | Uri-Path: "temperature" 4564 | | | | 4565 | | | | 4566 |<------------+ | | Header: 2.05 (T=NON, Code=69, MID=0x60b1) 4567 | 2.05 | | | Token: 0x86 4568 | | | | Payload: "22.3 C" 4569 | | | | 4570 | | | | 4571 | X------------+ | Header: 2.05 (T=NON, Code=69, MID=0x01a0) 4572 | 2.05 | | | Token: 0x86 4573 | | | | Payload: "20.9 C" 4574 | | | | 4575 | | | | 4576 |<------------------+ Header: 4.04 (T=NON, Code=132, MID=0x952a) 4577 | 4.04 | | | Token: 0x86 4578 | | | | 4580 Figure 22: Non-confirmable request (multicast); Non-confirmable 4581 response 4583 Appendix B. URI Examples 4585 The following examples demonstrate different sets of Uri options, and 4586 the result after constructing an URI from them. In addition to the 4587 options, Section 6.5 refers to the destination IP address and port, 4588 but not all paths of the algorithm cause the destination IP address 4589 and port to be included in the URI. 4591 o Input: 4593 Destination IP Address = [2001:db8::2:1] 4594 Destination UDP Port = 5683 4596 Output: 4598 coap://[2001:db8::2:1]/ 4600 o Input: 4602 Destination IP Address = [2001:db8::2:1] 4603 Destination UDP Port = 5683 4604 Uri-Host = "example.net" 4606 Output: 4608 coap://example.net/ 4610 o Input: 4612 Destination IP Address = [2001:db8::2:1] 4613 Destination UDP Port = 5683 4614 Uri-Host = "example.net" 4615 Uri-Path = ".well-known" 4616 Uri-Path = "core" 4618 Output: 4620 coap://example.net/.well-known/core 4622 o Input: 4624 Destination IP Address = [2001:db8::2:1] 4625 Destination UDP Port = 5683 4626 Uri-Host = "xn--18j4d.example" 4627 Uri-Path = the string composed of the Unicode characters U+3053 4628 U+3093 U+306b U+3061 U+306f, usually represented in UTF-8 as 4629 E38193E38293E381ABE381A1E381AF hexadecimal 4631 Output: 4633 coap:// 4634 xn--18j4d.example/%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF 4636 (The line break has been inserted for readability; it is not 4637 part of the URI.) 4639 o Input: 4641 Destination IP Address = 198.51.100.1 4642 Destination UDP Port = 61616 4643 Uri-Path = "" 4644 Uri-Path = "/" 4645 Uri-Path = "" 4646 Uri-Path = "" 4647 Uri-Query = "//" 4648 Uri-Query = "?&" 4650 Output: 4652 coap://198.51.100.1:61616//%2F//?%2F%2F&?%26 4654 Appendix C. Changelog 4656 (To be removed by RFC editor before publication.) 4658 Changed from ietf-13 to ietf-14: 4660 o Made Accept option non-repeatable. 4662 o Clarified that Safe options in a 2.03 Valid response update the 4663 cache. 4665 o Clarified that payload sniffing is acceptable only if no Content- 4666 Format was supplied. 4668 o Clarified URI examples (Appendix B). 4670 o Numerous editorial improvements and clarifications. 4672 Changed from ietf-12 to ietf-13: 4674 o Simplified message format. 4676 * Removed the OC (Option Count) field in the CoAP Header. 4678 * Changed the End-of-Options Marker into the Payload Marker. 4680 * Changed the format of Options: use 4 bits for option length and 4681 delta; insert one or two additional bytes after the option 4682 header if necessary. 4684 * Promoted the Token Option to a field following the CoAP Header. 4686 o Clarified when a payload is a diagnostic payload (#264). 4688 o Moved IPsec discussion to separate draft (#262). 4690 o Added a reference to a separate draft on reverse-proxy URI 4691 embedding (#259). 4693 o Clarified the use of ETags and of 2.03 responses (#265, #254, 4694 #256). 4696 o Added reserved Location-* numbers and clarified Location-*. 4698 o Added Proxy-Scheme proposal. 4700 o Clarified terms such as content negotiation, selected 4701 representation, representation-format, message format error. 4703 o Numerous clarifications and a few bugfixes. 4705 Changed from ietf-11 to ietf-12: 4707 o Extended options to support lengths of up to 1034 bytes (#202). 4709 o Added new Jump mechanism for options and removed Fenceposting 4710 (#214). 4712 o Added new IANA option number registration policy (#214). 4714 o Added Proxy Unsafe/Safe and Cache-Key masking to option numbers 4715 (#241). 4717 o Re-numbered option numbers to use Unsafe/Safe and Cache-Key 4718 compliant numbers (#241). 4720 o Defined NSTART and restricted the value to 1 with a MUST (#215). 4722 o Defined PROBING_RATE and set it to 1 Byte/second (#215). 4724 o Defined DEFAULT_LEISURE (#246). 4726 o Renamed Content-Type into Content-Format, and Media Type registry 4727 into Content-Format registry. 4729 o A large number of small editorial changes, clarifications and 4730 improvements have been made. 4732 Changed from ietf-10 to ietf-11: 4734 o Expanded section 4.8 on Transmission Parameters, and used the 4735 derived values defined there (#201). Changed parameter names to 4736 be shorter and more to the point. 4738 o Several more small editorial changes, clarifications and 4739 improvements have been made. 4741 Changed from ietf-09 to ietf-10: 4743 o Option deltas are restricted to 0 to 14; the option delta 15 is 4744 used exclusively for the end-of-options marker (#239). 4746 o Option numbers that are a multiple of 14 are not reserved, but are 4747 required to have an empty default value (#212). 4749 o Fixed misleading language that was introduced in 5.10.2 in coap-07 4750 re Uri-Host and Uri-Port (#208). 4752 o Segments and arguments can have a length of zero characters 4753 (#213). 4755 o The Location-* options describe together describe one location. 4756 The location is a relative URI, not an "absolute path URI" (#218). 4758 o The value of the Location-Path Option must not be '.' or '..' 4759 (#218). 4761 o Added a sentence on constructing URIs from Location-* options 4762 (#231). 4764 o Reserved option numbers for future Location-* options (#230). 4766 o Fixed response codes with payload inconsistency (#233). 4768 o Added advice on default values for critical options (#207). 4770 o Clarified use of identifiers in RawPublicKey Mode Provisioning 4771 (#222). 4773 o Moved "Securing CoAP" out of the "Security Considerations" (#229). 4775 o Added "All CoAP Nodes" multicast addresses to "IANA 4776 Considerations" (#216). 4778 o Over 100 small editorial changes, clarifications and improvements 4779 have been made. 4781 Changed from ietf-08 to ietf-09: 4783 o Improved consistency of statements about RST on NON: RST is a 4784 valid response to a NON message (#183). 4786 o Clarified that the protocol constants can be configured for 4787 specific application environments. 4789 o Added implementation note recommending piggy-backing whenever 4790 possible (#182). 4792 o Added a content-encoding column to the media type registry (#181). 4794 o Minor improvements to Appendix D. 4796 o Added text about multicast response suppression (#177). 4798 o Included the new End-of-options Marker (#176). 4800 o Added a reference to draft-ietf-tls-oob-pubkey and updated the RPK 4801 text accordingly. 4803 Changed from ietf-07 to ietf-08: 4805 o Clarified matching rules for messages (#175) 4807 o Fixed a bug in Section 8.2.2 on Etags (#168) 4809 o Added an IP address spoofing threat analysis contribution (#167) 4811 o Re-focused the security section on raw public keys (#166) 4813 o Added an 4.06 error to Accept (#165) 4815 Changed from ietf-06 to ietf-07: 4817 o application/link-format added to Media types registration (#160) 4819 o Moved content-type attribute to the document from link-format. 4821 o Added coaps scheme and DTLS-secured CoAP default port (#154) 4823 o Allowed 0-length Content-type options (#150) 4825 o Added congestion control recommendations (#153) 4827 o Improved text on PUT/POST response payloads (#149) 4829 o Added an Accept option for content-negotiation (#163) 4831 o Added If-Match and If-None-Match options (#155) 4833 o Improved Token Option explanation (#147) 4835 o Clarified mandatory to implement security (#156) 4837 o Added first come first server policy for 2-byte Media type codes 4838 (#161) 4840 o Clarify matching rules for messages and tokens (#151) 4842 o Changed OPTIONS and TRACE to always return 501 in HTTP-CoAP 4843 mapping (#164) 4845 Changed from ietf-05 to ietf-06: 4847 o HTTP mapping section improved with the minimal protocol standard 4848 text for CoAP-HTTP and HTTP-CoAP forward proxying (#137). 4850 o Eradicated percent-encoding by including one Uri-Query Option per 4851 &-delimited argument in a query. 4853 o Allowed RST message in reply to a NON message with unexpected 4854 token (#135). 4856 o Cache Invalidation only happens upon successful responses (#134). 4858 o 50% jitter added to the initial retransmit timer (#142). 4860 o DTLS cipher suites aligned with ZigBee IP, DTLS clarified as 4861 default CoAP security mechanism (#138, #139) 4863 o Added a minimal reference to draft-kivinen-ipsecme-ikev2-minimal 4864 (#140). 4866 o Clarified the comparison of UTF-8s (#136). 4868 o Minimized the initial media type registry (#101). 4870 Changed from ietf-04 to ietf-05: 4872 o Renamed Immediate into Piggy-backed and Deferred into Separate -- 4873 should finally end the confusion on what this is about. 4875 o GET requests now return a 2.05 (Content) response instead of 2.00 4876 (OK) response (#104). 4878 o Added text to allow 2.02 (Deleted) responses in reply to POST 4879 requests (#105). 4881 o Improved message deduplication rules (#106). 4883 o Section added on message size implementation considerations 4884 (#103). 4886 o Clarification made on human readable error payloads (#109). 4888 o Definition of CoAP methods improved (#108). 4890 o Max-Age removed from requests (#107). 4892 o Clarified uniqueness of tokens (#112). 4894 o Location-Query Option added (#113). 4896 o ETag length set to 1-8 bytes (#123). 4898 o Clarified relation between elective/critical and option numbers 4899 (#110). 4901 o Defined when to update Version header field (#111). 4903 o URI scheme registration improved (#102). 4905 o Added review guidelines for new CoAP codes and numbers. 4907 Changes from ietf-03 to ietf-04: 4909 o Major document reorganization (#51, #63, #71, #81). 4911 o Max-age length set to 0-4 bytes (#30). 4913 o Added variable unsigned integer definition (#31). 4915 o Clarification made on human readable error payloads (#50). 4917 o Definition of POST improved (#52). 4919 o Token length changed to 0-8 bytes (#53). 4921 o Section added on multiplexing CoAP, DTLS and STUN (#56). 4923 o Added cross-protocol attack considerations (#61). 4925 o Used new Immediate/Deferred response definitions (#73). 4927 o Improved request/response matching rules (#74). 4929 o Removed unnecessary media types and added recommendations for 4930 their use in M2M (#76). 4932 o Response codes changed to base 32 coding, new Y.XX naming (#77). 4934 o References updated as per AD review (#79). 4936 o IANA section completed (#80). 4938 o Proxy-Uri Option added to disambiguate between proxy and non-proxy 4939 requests (#82). 4941 o Added text on critical options in cached states (#83). 4943 o HTTP mapping sections improved (#88). 4945 o Added text on reverse proxies (#72). 4947 o Some security text on multicast added (#54). 4949 o Trust model text added to introduction (#58, #60). 4951 o AES-CCM vs. AES-CCB text added (#55). 4953 o Text added about device capabilities (#59). 4955 o DTLS section improvements (#87). 4957 o Caching semantics aligned with RFC2616 (#78). 4959 o Uri-Path Option split into multiple path segments. 4961 o MAX_RETRANSMIT changed to 4 to adjust for RESPONSE_TIME = 2. 4963 Changes from ietf-02 to ietf-03: 4965 o Token Option and related use in asynchronous requests added (#25). 4967 o CoAP specific error codes added (#26). 4969 o Erroring out on unknown critical options changed to a MUST (#27). 4971 o Uri-Query Option added. 4973 o Terminology and definitions of URIs improved. 4975 o Security section completed (#22). 4977 Changes from ietf-01 to ietf-02: 4979 o Sending an error on a critical option clarified (#18). 4981 o Clarification on behavior of PUT and idempotent operations (#19). 4983 o Use of Uri-Authority clarified along with server processing rules; 4984 Uri-Scheme Option removed (#20, #23). 4986 o Resource discovery section removed to a separate CoRE Link Format 4987 draft (#21). 4989 o Initial security section outline added. 4991 Changes from ietf-00 to ietf-01: 4993 o New cleaner transaction message model and header (#5). 4995 o Removed subscription while being designed (#1). 4997 o Section 2 re-written (#3). 4999 o Text added about use of short URIs (#4). 5001 o Improved header option scheme (#5, #14). 5003 o Date option removed whiled being designed (#6). 5005 o New text for CoAP default port (#7). 5007 o Completed proxying section (#8). 5009 o Completed resource discovery section (#9). 5011 o Completed HTTP mapping section (#10). 5013 o Several new examples added (#11). 5015 o URI split into 3 options (#12). 5017 o MIME type defined for link-format (#13, #16). 5019 o New text on maximum message size (#15). 5021 o Location Option added. 5023 Changes from shelby-01 to ietf-00: 5025 o Removed the TCP binding section, left open for the future. 5027 o Fixed a bug in the example. 5029 o Marked current Sub/Notify as (Experimental) while under WG 5030 discussion. 5032 o Fixed maximum datagram size to 1280 for both IPv4 and IPv6 (for 5033 CoAP-CoAP proxying to work). 5035 o Temporarily removed the Magic Byte header as TCP is no longer 5036 included as a binding. 5038 o Removed the Uri-code Option as different URI encoding schemes are 5039 being discussed. 5041 o Changed the rel= field to desc= for resource discovery. 5043 o Changed the maximum message size to 1024 bytes to allow for IP/UDP 5044 headers. 5046 o Made the URI slash optimization and method idempotence MUSTs 5048 o Minor editing and bug fixing. 5050 Changes from shelby-00 to shelby-01: 5052 o Unified the message header and added a notify message type. 5054 o Renamed methods with HTTP names and removed the NOTIFY method. 5056 o Added a number of options field to the header. 5058 o Combines the Option Type and Length into an 8-bit field. 5060 o Added the magic byte header. 5062 o Added new ETag Option. 5064 o Added new Date Option. 5066 o Added new Subscription Option. 5068 o Completed the HTTP Code - CoAP Code mapping table appendix. 5070 o Completed the Content-type Identifier appendix and tables. 5072 o Added more simplifications for URI support. 5074 o Initial subscription and discovery sections. 5076 o A Flag requirements simplified. 5078 Authors' Addresses 5080 Zach Shelby 5081 Sensinode 5082 Kidekuja 2 5083 Vuokatti 88600 5084 Finland 5086 Phone: +358407796297 5087 Email: zach@sensinode.com 5089 Klaus Hartke 5090 Universitaet Bremen TZI 5091 Postfach 330440 5092 Bremen D-28359 5093 Germany 5095 Phone: +49-421-218-63905 5096 Email: hartke@tzi.org 5098 Carsten Bormann 5099 Universitaet Bremen TZI 5100 Postfach 330440 5101 Bremen D-28359 5102 Germany 5104 Phone: +49-421-218-63921 5105 Email: cabo@tzi.org