<?xml version="1.0" encoding="utf-8"?>
  <?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
  <!-- generated by https://github.com/cabo/kramdown-rfc2629 version 1.0.30 -->

<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
]>

<?rfc strict="yes"?>
<?rfc toc="yes"?>
<?rfc tocdepth="2"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc compact="no"?>
<?rfc subcompact="no"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>

<rfc ipr="trust200902" docName="draft-ietf-core-coap-tcp-tls-03" category="std">

  <front>
    <title abbrev="TCP/TLS/WebSockets Transports for CoAP">CoAP (Constrained Application Protocol) over TCP, TLS, and WebSockets</title>

    <author initials="C." surname="Bormann" fullname="Carsten Bormann">
      <organization>Universitaet Bremen TZI</organization>
      <address>
        <postal>
          <street>Postfach 330440</street>
          <city>Bremen</city>
          <code>D-28359</code>
          <country>Germany</country>
        </postal>
        <phone>+49-421-218-63921</phone>
        <email>cabo@tzi.org</email>
      </address>
    </author>
    <author initials="S." surname="Lemay" fullname="Simon Lemay">
      <organization>Zebra Technologies</organization>
      <address>
        <postal>
          <street>820 W. Jackson Blvd. Suite 700</street>
          <city>Chicago</city>
          <code>60607</code>
          <country>United States of America</country>
        </postal>
        <phone>+1-847-634-6700</phone>
        <email>slemay@zebra.com</email>
      </address>
    </author>
    <author initials="H." surname="Tschofenig" fullname="Hannes Tschofenig">
      <organization>ARM Ltd.</organization>
      <address>
        <postal>
          <street>110 Fulbourn Rd</street>
          <city>Cambridge</city>
          <code>CB1 9NJ</code>
          <country>Great Britain</country>
        </postal>
        <email>Hannes.tschofenig@gmx.net</email>
        <uri>http://www.tschofenig.priv.at</uri>
      </address>
    </author>
    <author initials="K." surname="Hartke" fullname="Klaus Hartke">
      <organization>Universitaet Bremen TZI</organization>
      <address>
        <postal>
          <street>Postfach 330440</street>
          <city>Bremen</city>
          <code>D-28359</code>
          <country>Germany</country>
        </postal>
        <phone>+49-421-218-63905</phone>
        <email>hartke@tzi.org</email>
      </address>
    </author>
    <author initials="B." surname="Silverajan" fullname="Bilhanan Silverajan">
      <organization>Tampere University of Technology</organization>
      <address>
        <postal>
          <street>Korkeakoulunkatu 10</street>
          <city>Tampere</city>
          <code>FI-33720</code>
          <country>Finland</country>
        </postal>
        <email>bilhanan.silverajan@tut.fi</email>
      </address>
    </author>
    <author initials="B." surname="Raymor" fullname="Brian Raymor" role="editor">
      <organization>Microsoft</organization>
      <address>
        <postal>
          <street>One Microsoft Way</street>
          <city>Redmond</city>
          <code>98052</code>
          <country>United States of America</country>
        </postal>
        <email>brian.raymor@microsoft.com</email>
      </address>
    </author>

    <date year="2016" month="July" day="08"/>

    <area>Applications Area (app)</area>
    <workgroup>CORE</workgroup>
    

    <abstract>


<t>The Constrained Application Protocol (CoAP), although inspired by HTTP, was designed to use UDP
instead of TCP. The message layer of the CoAP over UDP protocol includes support for
reliable delivery, simple congestion control, and flow control.</t>

<t>Some environments benefit from the availability of CoAP carried over reliable
transports such as TCP or TLS. This document outlines the changes required to use
CoAP over TCP, TLS, and WebSockets transports.</t>



    </abstract>


  </front>

  <middle>


<section anchor="introduction" title="Introduction">

<t>The <xref target="RFC7252">Constrained Application Protocol (CoAP)</xref> was designed
for Internet of Things (IoT) deployments, assuming that UDP <xref target="RFC0768"/> 
or DTLS <xref target="RFC6347"/> over UDP can be used unimpeded. UDP is a good choice
for transferring small amounts of data across networks that follow the IP
architecture.</t>

<t>Some CoAP deployments need to integrate well with existing enterprise
infrastructures, where UDP-based protocols may not be well-received or may
even be blocked by firewalls. Middleboxes that are unaware of CoAP usage for
IoT can make the use of UDP brittle, resulting in lost or malformed packets.</t>

<t>To address such environments, this document defines how to transport CoAP over TCP, 
CoAP over TLS, and CoAP over WebSockets. <xref target="layering"/> illustrates the layering:</t>

<figure title="Layering of CoAP over Reliable Transports" anchor="layering"><artwork align="center"><![CDATA[
        +--------------------------------+
        |          Application           |
        +--------------------------------+
        +--------------------------------+
        |  Requests/Responses/Signaling  |  CoAP (RFC 7252) / This Document
        |--------------------------------|
        |        Message Framing         |  This Document
        +--------------------------------+
        |      Reliable Transport        |
        +--------------------------------+
]]></artwork></figure>

<t>Where NATs are present, CoAP over TCP can help with their traversal.
NATs often calculate expiration timers based on the transport layer protocol
being used by application protocols. Many NATs maintain TCP-based NAT bindings
for longer periods based on the assumption that a transport layer protocol, such
as TCP, offers additional information about the session life cycle. UDP, on the other
hand, does not provide such information to a NAT and timeouts tend to be much 
shorter <xref target="HomeGateway"/>.</t>

<t>Some environments may also benefit from the ability of TCP to exchange
larger payloads, such as firmware images, without application layer
segmentation and to utilize the more sophisticated congestion control
capabilities provided by many TCP implementations.</t>

<t>CoAP may be integrated into a Web environment where the front-end
uses CoAP over UDP from IoT devices to a cloud infrastructure and then CoAP
over TCP between the back-end services. A TCP-to-UDP gateway can be used at
the cloud boundary to communicate with the UDP-based IoT device.</t>

<t>To allow IoT devices to better communicate in these demanding environments, CoAP
needs to support different transport protocols, namely TCP <xref target="RFC0793"/>,
in some situations secured by TLS <xref target="RFC5246"/>.</t>

<t>In addition, some corporate networks only allow Internet access via a HTTP proxy.
In this case, the best transport for CoAP would be the <xref target="RFC6455">WebSocket Protocol</xref>.
The WebSocket protocol provides two-way communication between a client
and a server after upgrading an <xref target="RFC7230">HTTP/1.1</xref> connection and may
be available in an environment that blocks CoAP over UDP. Another scenario
for CoAP over WebSockets is a CoAP application running inside a web browser
without access to connectivity other than HTTP and WebSockets.</t>

<t>This document specifies how to access resources using CoAP requests
and responses over the TCP/TLS and WebSocket protocols. This allows
connectivity-limited applications to obtain end-to-end CoAP
connectivity either by communicating CoAP directly with a CoAP server
accessible over a TCP/TLS or WebSocket connection or via a CoAP intermediary
that proxies CoAP requests and responses between different transports,
such as between WebSockets and UDP.</t>

<section anchor="terminology" title="Terminology">

<t>The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”,
“SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and
“OPTIONAL” in this document are to be interpreted as described in <xref target="RFC2119"/>.</t>

<t>This document assumes that readers are familiar with the terms and
concepts that are used in <xref target="RFC6455"/> and <xref target="RFC7252"/>.</t>

<t><list style="hanging">
  <t hangText='BERT Option:'><vspace blankLines='0'/>
  A Block1 or Block2 option that includes an SZX value of 7.</t>
</list></t>
<t><list style="hanging">
  <t hangText='BERT Block:'><vspace blankLines='0'/>
  The payload of a CoAP message that is affected by a BERT Option in
descriptive usage (Section 2.1 of <xref target="I-D.ietf-core-block"/>).</t>
</list></t>

</section>
</section>
<section anchor="coap-over-tcp" title="CoAP over TCP">

<t>The request/response interaction model of CoAP over TCP is the same as CoAP over UDP.
The primary differences are in the message layer. CoAP over UDP supports optional
reliability by defining four types of messages: Confirmable, Non-confirmable,
Acknowledgement, and Reset. TCP eliminates the need for the message layer
to support reliability. As a result, message types are not defined in CoAP over TCP.</t>

<section anchor="messaging-model" title="Messaging Model">

<t>Conceptually, CoAP over TCP replaces most of the CoAP over UDP message layer
with a framing mechanism on top of the byte stream provided by TCP/TLS,
conveying the length information for each message that on datagram transports
is provided by the UDP/DTLS datagram layer.</t>

<t>TCP ensures reliable message transmission, so the CoAP over TCP messaging
layer is not required to support acknowledgements or detection of duplicate
messages. As a result, both the Type and Message ID fields are no longer required
and are removed from the CoAP over TCP message format. All messages are also untyped.</t>

<t><xref target="fig-flow-comparison"/> illustrates the difference between CoAP over UDP and
CoAP over reliable transport. The removed Type (no type) and Message ID fields
are indicated by dashes.</t>

<figure title="Comparison between CoAP over unreliable and reliable transport." anchor="fig-flow-comparison"><artwork align="center"><![CDATA[
 Client                Server   Client                Server
    |                    |         |                    |
    |   CON [0xbc90]     |         | (-------) [------] |
    | GET /temperature   |         | GET /temperature   |
    |   (Token 0x71)     |         |   (Token 0x71)     |
    +------------------->|         +------------------->|
    |                    |         |                    |
    |   ACK [0xbc90]     |         | (-------) [------] |
    |   2.05 Content     |         |   2.05 Content     |
    |   (Token 0x71)     |         |   (Token 0x71)     |
    |     "22.5 C"       |         |     "22.5 C"       |
    |<-------------------+         |<-------------------+
    |                    |         |                    |

        CoAP over UDP                CoAP over reliable
                                         transport
]]></artwork></figure>

</section>
<section anchor="udp-to-tcp-gateways" title="UDP-to-TCP gateways">

<t>A UDP-to-TCP gateway MUST discard all Empty messages (Code 0.00) after processing at the
message layer. For Confirmable (CON), Non-Confirmable (NOM), and Acknowledgement
(ACK) messages that are not Empty, their contents are repackaged into untyped
messages.</t>

</section>
<section anchor="tcp-message-format" title="Message Format">

<t>The CoAP message format defined in <xref target="RFC7252"/>, as shown in 
<xref target="CoAP-Header"/>, relies on the datagram transport (UDP, or DTLS over
UDP) for keeping the individual messages separate and for providing 
length information.</t>

<figure title="RFC 7252 defined CoAP Message Format." anchor="CoAP-Header"><artwork><![CDATA[
 0                   1                   2                   3
 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Ver| T |  TKL  |      Code     |          Message ID           |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   Token (if any, TKL bytes) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   Options (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 1 1 1 1 1 1 1|    Payload (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
]]></artwork></figure>

<t>The CoAP over TCP message format is very similar to the format
specified for CoAP over UDP. The differences are as follows:</t>

<t><list style="symbols">
  <t>Since the underlying TCP connection provides retransmissions and
deduplication, there is no need for the reliability mechanisms
provided by CoAP over UDP. The “T” and “Message ID” fields in
the CoAP message header are elided.</t>
  <t>The “Ver” field is elided as well. In constrast to the UDP message
layer for UDP and DTLS, the CoAP over TCP message layer does not
send a version number in each message. If required in the future,
a new Capability and Settings Option (See <xref target="negotiation"/>) could be
defined to support version negotiation.</t>
  <t>In a stream oriented transport protocol such as TCP, a form of message 
delimitation is needed. For this purpose, CoAP over TCP introduces a 
length field with variable size. <xref target="fig-frame"/> shows the adjusted CoAP 
message format with a modified structure for the fixed header (first 4
bytes of the CoAP over UDP header), which includes the length information of
variable size, shown here as an 8-bit length.</t>
</list></t>

<figure title="CoAP frame with 8-bit Extended Length field." anchor="fig-frame"><artwork><![CDATA[
 0                   1                   2                   3
 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Len=13 |  TKL  |Extended Length|      Code     | TKL bytes ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Options (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 1 1 1 1 1 1 1|    Payload (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
]]></artwork></figure>

<t><list style="hanging">
  <t hangText='Length (Len):'>
  4-bit unsigned integer. A value between 0 and 12 directly indicates the
length of the message in bytes starting with the first bit of the Options
field. Three values are reserved for special constructs:

      <list style="hanging">
        <t hangText='13:'>
        An 8-bit unsigned integer (Extended Length) follows the initial byte and indicates
the length of options/payload minus 13.</t>
        <t hangText='14:'>
        A 16-bit unsigned integer (Extended Length) in network byte order follows the
initial byte and indicates the length of options/payload minus
269.</t>
        <t hangText='15:'>
        A 32-bit unsigned integer (Extended Length) in network byte order follows the
initial byte and indicates the length of options/payload minus
65805.</t>
      </list>
  </t>
</list></t>

<t>The encoding of the Length field is modeled on CoAP Options (see section 3.1 of <xref target="RFC7252"/>).</t>

<t>The following figures show the message format for the 0-bit, 16-bit, and 
the 32-bit variable length cases.</t>

<figure title="CoAP message format without an Extended Length field." anchor="fig-frame1"><artwork><![CDATA[
 0                   1                   2                   3
 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Len  |  TKL  |      Code     | Token (if any, TKL bytes) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Options (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 1 1 1 1 1 1 1|    Payload (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
]]></artwork></figure>

<t>For example: A CoAP message just containing a 2.03 code with the
token 7f and no options or payload would be encoded as shown in <xref target="fig-frame2"/>.</t>

<figure title="CoAP message with no options or payload." anchor="fig-frame2"><artwork><![CDATA[
 0                   1                   2
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      0x01     |      0x43     |      0x7f     |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

 Len   =    0 ------>  0x01
 TKL   =    1 ___/
 Code  =  2.03     --> 0x43
 Token =               0x7f
]]></artwork></figure>

<figure title="CoAP message format with 16-bit Extended Length field." anchor="fig-frame3"><artwork><![CDATA[
 0                   1                   2                   3
 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Len=14 |  TKL  | Extended Length (16 bits)     |   Code        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   Token (if any, TKL bytes) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   Options (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 1 1 1 1 1 1 1|    Payload (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
]]></artwork></figure>

<figure title="CoAP message format with 32-bit Extended Length field." anchor="fig-frame4"><artwork><![CDATA[
 0                   1                   2                   3
 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|Len=15 |  TKL  | Extended Length (32 bits)                              
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               |    Code       |  Token (if any, TKL bytes) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   Options (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 1 1 1 1 1 1 1|    Payload (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
]]></artwork></figure>

<t>The semantics of the other CoAP header fields are left unchanged.</t>

</section>
<section anchor="message-transmission" title="Message Transmission">

<t>CoAP requests and responses are exchanged asynchronously over the
TCP/TLS connection. A CoAP client can send multiple requests
without waiting for a response and the CoAP server can return
responses in any order. Responses MUST be returned over the same
connection as the originating request. Concurrent requests are
differentiated by their Token, which is scoped locally to the
connection.</t>

<t>The connection is bi-directional, so requests can be sent both by
the entity that established the connection and the remote host.</t>

<t>Retransmission and deduplication of messages is provided by the
TCP/TLS protocol.</t>

<t>Since the TCP protocol provides ordered delivery of messages,
the mechanism for reordering detection when <xref target="RFC7641">observing resources</xref>
is not needed. The value of the Observe Option in notifications MAY be
empty on transmission and MUST be ignored on reception.</t>

</section>
</section>
<section anchor="websockets-overview" title="CoAP over WebSockets">

<t>CoAP over WebSockets can be used in a number of configurations. The
most basic configuration is a CoAP client retrieving or updating a
CoAP resource located at a CoAP server that exposes a WebSocket endpoint
(<xref target="arch-1"/>). The CoAP client acts as the WebSocket client, establishes
a WebSocket connection, and sends a CoAP request, to which the CoAP server
returns a CoAP response. The WebSocket connection can be used for any number
of requests.</t>

<figure title="CoAP Client (WebSocket client) accesses CoAP Server (WebSocket server)" anchor="arch-1"><artwork align="center"><![CDATA[
 ___________                            ___________
|           |                          |           |
|          _|___      requests      ___|_          |
|   CoAP  /  \  \  ------------->  /  /  \  CoAP   |
|  Client \__/__/  <-------------  \__\__/ Server  |
|           |         responses        |           |
|___________|                          |___________|
        WebSocket  =============>  WebSocket
          Client     Connection     Server
]]></artwork></figure>

<t>The challenge with this configuration is how to identify a resource in the
namespace of the CoAP server. When the WebSocket protocol is used by
a dedicated client directly (i.e., not from a web page through a web browser),
the client can connect to any WebSocket endpoint. This means it is necessary for
the client to identify both the WebSocket endpoint (identified
by a “ws” or “wss” URI) and the path and query of the CoAP resource within
that endpoint from the same URI. When the WebSocket protocol is used
from a web page, the choices are more limited <xref target="RFC6454"/>, but the challenge persists.</t>

<t><xref target="uris"/> defines a new “coap+ws” URI scheme that identifies both a WebSocket endpoint
and a resource within that endpoint as follows:</t>

<figure title="The &quot;coap+ws&quot; URI Scheme" anchor="uri-example"><artwork align="center"><![CDATA[
      coap+ws://example.org/sensors/temperature?u=Cel
           \______  ______/\___________  ___________/
                  \/                   \/
                                     Uri-Path: "sensors"
ws://example.org/.well-known/coap    Uri-Path: "temperature"
                                     Uri-Query: "u=Cel"
]]></artwork></figure>

<t>Another possible configuration is to set up a CoAP forward proxy
at the WebSocket endpoint. Depending on what transports are available
to the proxy, it could forward the request to a CoAP server with a
CoAP UDP endpoint (<xref target="arch-2"/>), an SMS endpoint (a.k.a. mobile phone),
or even another WebSocket endpoint. The client specifies the resource to be
updated or retrieved in the Proxy-URI Option.</t>

<figure title="CoAP Client (WebSocket client) accesses CoAP Server (UDP server) via a CoAP proxy (WebSocket server/UDP client)" anchor="arch-2"><artwork align="center"><![CDATA[
 ___________                ___________                ___________
|           |              |           |              |           |
|          _|___        ___|_         _|___        ___|_          |
|   CoAP  /  \  \ ---> /  /  \ CoAP  /  \  \ ---> /  /  \  CoAP   |
|  Client \__/__/ <--- \__\__/ Proxy \__/__/ <--- \__\__/ Server  |
|           |              |           |              |           |
|___________|              |___________|              |___________|
        WebSocket ===> WebSocket      UDP            UDP
          Client        Server      Client          Server
]]></artwork></figure>

<t>A third possible configuration is a CoAP server running inside a web browser
(<xref target="arch-3"/>). The web browser initially connects to a WebSocket endpoint and
is then reachable through the WebSocket server. When no connection exists, the
CoAP server is unreachable. Because the WebSocket server is the only way to
reach the CoAP server, the CoAP proxy should be a Reverse Proxy.</t>

<figure title="CoAP Client (UDP client) accesses sleepy CoAP Server (WebSocket client) via a CoAP proxy (UDP server/WebSocket server)" anchor="arch-3"><artwork align="center"><![CDATA[
 ___________                ___________                ___________
|           |              |           |              |           |
|          _|___        ___|_         _|___        ___|_          |
|   CoAP  /  \  \ ---> /  /  \ CoAP  /  /  \ ---> /  \  \  CoAP   |
|  Client \__/__/ <--- \__\__/ Proxy \__\__/ <--- \__/__/ Server  |
|           |              |           |              |           |
|___________|              |___________|              |___________|
           UDP            UDP      WebSocket <=== WebSocket
         Client          Server      Server        Client
]]></artwork></figure>

<t>Further configurations are possible, including those where a
WebSocket connection is established through an HTTP proxy.</t>

<t>CoAP over WebSockets is intentionally very similar to CoAP
over UDP. Therefore, instead of presenting CoAP over WebSockets as a
new protocol, this document specifies it as a series of deltas from
<xref target="RFC7252"/>.</t>

<section anchor="handshake" title="Opening Handshake">

<t>Before CoAP requests and responses are exchanged, a WebSocket
connection is established as defined in Section 4 of <xref target="RFC6455"/>.
<xref target="handshake-example"/> shows an example.</t>

<t>The WebSocket client MUST include the subprotocol name “coap” in
the list of protocols, which indicates support for the protocol
defined in this document. Any later, incompatible versions of
CoAP or CoAP over WebSockets will use a different subprotocol
name.</t>

<t>The WebSocket client includes the hostname of the WebSocket server
in the Host header field of its handshake as per <xref target="RFC6455"/>. The Host
header field also indicates the default value of the Uri-Host Option in
requests from the WebSocket client to the WebSocket server.</t>

<figure title="Example of an Opening Handshake" anchor="handshake-example"><artwork align="center"><![CDATA[
GET /.well-known/coap HTTP/1.1
Host: example.org
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Protocol: coap
Sec-WebSocket-Version: 13

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Sec-WebSocket-Protocol: coap
]]></artwork></figure>

</section>
<section anchor="websocket-message-format" title="Message Format">

<t>Once a WebSocket connection is established, CoAP requests and
responses can be exchanged as WebSocket messages. Since CoAP uses a
binary message format, the messages are transmitted in binary data
frames as specified in Sections 5 and 6 of <xref target="RFC6455"/>.</t>

<t>The message format shown in <xref target="ws-message-format"/> is the same as the CoAP
over TCP message format (see <xref target="tcp-message-format"/>) with one restriction. The
Length (Len) field MUST be set to zero because the WebSockets frame contains
the length.</t>

<figure title="CoAP Message Format over WebSockets" anchor="ws-message-format"><artwork align="center"><![CDATA[
  0                   1                   2                   3
 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   Len |  TKL  |      Code     |    Token (TKL bytes) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   Options (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|1 1 1 1 1 1 1 1|    Payload (if any) ...
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
]]></artwork></figure>

<t>The CoAP over TCP message format eliminates the Version field defined in
CoAP over UDP. If CoAP version negotiation is required in the future,
CoAP over WebSockets can address the requirement by the definition of a
new subprotocol identifier that is negotiated during the opening handshake.</t>

<t>Requests and response messages can be fragmented as specified in
Section 5.4 of <xref target="RFC6455"/>, though typically they are sent unfragmented
as they tend to be small and fully buffered before transmission. The WebSocket
protocol does not provide means for multiplexing. If it is not desirable for a
large message to monopolize the connection, requests and responses can be
transferred in a block-wise fashion as defined in <xref target="I-D.ietf-core-block"/>.</t>

<t>Empty messages (Code 0.00) MUST be ignored by the recipient (see also
<xref target="sec-ping"/>).</t>

</section>
<section anchor="requests-responses" title="Message Transmission">

<t>CoAP requests and responses are exchanged asynchronously over the
WebSocket connection. A CoAP client can send multiple requests
without waiting for a response and the CoAP server can return
responses in any order. Responses MUST be returned over the same
connection as the originating request. Concurrent requests are
differentiated by their Token, which is scoped locally to the
connection.</t>

<t>The connection is bi-directional, so requests can be sent both by
the entity that established the connection and the remote host.</t>

<t>Retransmission and deduplication of messages is provided by the
WebSocket protocol. CoAP over WebSockets therefore does not make a
distinction between Confirmable or Non-Confirmable messages, and does
not provide Acknowledgement or Reset messages.</t>

<t>Since the WebSocket protocol provides ordered delivery of messages,
the mechanism for reordering detection when <xref target="RFC7641">observing resources</xref>
is not needed. The value of the Observe Option in notifications MAY
be empty on transmission and MUST be ignored on reception.</t>

</section>
<section anchor="liveliness" title="Connection Health">

<t>When a client does not receive any response for some time after
sending a CoAP request (or, similarly, when a client observes a
resource and it does not receive any notification for some time),
the connection between the WebSocket client and the WebSocket
server may be lost or temporarily disrupted without the client
being aware of it.</t>

<t>To check the health of the WebSocket connection (and thereby of all
active requests, if any), the client can send a Ping frame or an
unsolicited Pong frame as specified in Section 5.5 of
<xref target="RFC6455"/>. There is no way to retransmit a request without
creating a new one. Re-registering interest in a resource is
permitted, but entirely unnecessary.</t>

</section>
<section anchor="close" title="Closing the Connection">

<t>The WebSocket connection is closed as specified in Section 7 of <xref target="RFC6455"/>.</t>

<t>All requests for which the CoAP client has not received
a response yet are cancelled when the connection is closed.
If the client observes one or more resources over the WebSocket
connection, then the CoAP server (or intermediary in the role of
the CoAP server) MUST remove all entries associated with the client
from the lists of observers when the connection is closed.</t>

</section>
</section>
<section anchor="signaling" title="Signaling">

<t>Signaling messages are introduced to allow peers to:</t>

<t><list style="symbols">
  <t>Share characteristics such as maximum message size for the connection</t>
  <t>Shutdown the connection in an ordered fashion</t>
  <t>Terminate the connection in response to a serious error condition</t>
</list></t>

<t>Signaling is a third basic kind of message in CoAP, after requests and responses. 
Signaling messages share a common structure with the existing CoAP messages.
There is a code, a token, options, and an optional payload.</t>

<t>(See Section 3 of <xref target="RFC7252"/> for the overall structure, as adapted to the
specific transport.)</t>

<section anchor="signaling-codes" title="Signaling Codes">

<t>A code in the 7.01-7.31 range indicates a Signaling message. Values in this
range are assigned by the “CoAP Signaling Codes” sub-registry (see <xref target="message-codes"/>).</t>

<t>For each message, there is a sender and a peer receiving the message.</t>

<t>Payloads in Signaling messages are diagnostic payloads (see Section
5.5.2 of <xref target="RFC7252"/>), unless otherwise defined by a Signaling
message option.</t>

</section>
<section anchor="signaling-option-numbers" title="Signaling Option Numbers">

<t>Option numbers for Signaling messages are specific to the message
code. They do not share the number space with CoAP options for
request/response messages or with Signaling messages using other
codes.</t>

<t>Option numbers are assigned by the “CoAP Signaling Option Numbers”
sub-registry (see <xref target="option-codes"/>).</t>

<t>Signaling options are elective or critical as defined in Section 5.4.1
of <xref target="RFC7252"/>). If a Signaling option is critical and not understood by
the receiver, it MUST abort the connection (see <xref target="sec-abort"/>). If the
option is understood but cannot be processed, the option documents the behavior.</t>

</section>
<section anchor="capability-and-settings-messages-csm" title="Capability and Settings Messages (CSM)">

<t>Capability and Settings messages (CSM) are used for two purposes:</t>

<t><list style="symbols">
  <t>Each capability option advertises one capability of the sender to the recipient.</t>
  <t>Setting options indicate a setting that will be applied by the sender.</t>
</list></t>

<t>Most CSM Options are useful mainly as initial messages in the connection.</t>

<t>Both capability and settings options are cumulative. A Capability and Settings
message does not invalidate a previously sent capability indication or setting
even if it is not repeated. A capability message without any option is a no-operation (and
can be used as such). An option that is sent might override a previous value for
the same option. The option defines how to handle this case if needed.</t>

<t>Base values are listed below for CSM Options. These are the values for the
Capability and Setting before any Capability and Settings messages sends a
modified value.</t>

<t>These are not default values for the option as defined in Section 5.4.4 in <xref target="RFC7252"/>.
A default value would mean that an empty Capability and Settings message would result in
the option being set to its default value.</t>

<t>Capability and Settings messages are indicated by the 7.01 code (CSM).</t>

<section anchor="server-name-setting-option" title="Server-Name Setting Option">

<texttable>
      <ttcol align='left'>Number</ttcol>
      <ttcol align='left'>Applies to</ttcol>
      <ttcol align='left'>Name</ttcol>
      <ttcol align='right'>Format</ttcol>
      <ttcol align='right'>Length</ttcol>
      <ttcol align='right'>Base Value</ttcol>
      <c>1</c>
      <c>CSM</c>
      <c>Server-Name</c>
      <c>string</c>
      <c>1-255</c>
      <c>(see below)</c>
</texttable>

<t>A client can use the Server-Name critical option to indicate the default value
for the Uri-Host Options in the messages that it sends to the server.
It has the same restrictions as the Uri-Host Option (Section 5.10 of <xref target="RFC7252"/>.</t>

<t>For TLS, the initial value for the Server-Name Option is given by the SNI value.</t>

<t>For Websockets, the initial value for the Server-Name Option is given by the HTTP
Host header field.</t>

</section>
<section anchor="max-message-size-capability-option" title="Max-Message-Size Capability Option">

<t>The sender can use the Max-Message-Size elective option to indicate the maximum message size
in bytes that it can receive.</t>

<texttable>
      <ttcol align='left'>Number</ttcol>
      <ttcol align='left'>Applies to</ttcol>
      <ttcol align='left'>Name</ttcol>
      <ttcol align='right'>Format</ttcol>
      <ttcol align='right'>Length</ttcol>
      <ttcol align='right'>Base Value</ttcol>
      <c>2</c>
      <c>CSM</c>
      <c>Max-Message-Size</c>
      <c>uint</c>
      <c>0-4</c>
      <c>1152</c>
</texttable>

<t>As per Section 4.6 of <xref target="RFC7252"/>, the base value (and the value used when this option
is not implemented) is 1152. A peer that relies on this option being indicated with a
certain minimum value will enjoy limited interoperability.</t>

</section>
<section anchor="block-wise-transfer-capability-option" title="Block-wise Transfer Capability Option">

<texttable>
      <ttcol align='left'>Number</ttcol>
      <ttcol align='left'>Applies to</ttcol>
      <ttcol align='left'>Name</ttcol>
      <ttcol align='right'>Format</ttcol>
      <ttcol align='right'>Length</ttcol>
      <ttcol align='right'>Base Value</ttcol>
      <c>4</c>
      <c>CSM</c>
      <c>Block-wise Transfer</c>
      <c>empty</c>
      <c>0</c>
      <c>(none)</c>
</texttable>

<t>A sender can use the Block-wise Transfer elective Option to indicate that it
supports the block-wise transfer protocol <xref target="I-D.ietf-core-block"/>.</t>

<t>If the option is not given, the peer has no information about whether block-wise
transfers are supported by the sender or not. An implementation that supports
block-wise transfers SHOULD indicate the Block-wise Transfer Option. If a
Max-Message-Size Option is indicated with a value that is greater than 1152
(in the same or a different CSM message), the Block-wise Transfer Option also
indicates support for BERT (see <xref target="bert"/>).</t>

</section>
</section>
<section anchor="sec-ping" title="Ping and Pong Messages">

<t>In CoAP over TCP, Empty messages (Code 0.00) can always be sent and MUST be ignored
by the recipient (see also <xref target="sec-ping"/>). This provides a basic keep-alive function
that can refresh NAT bindings. In contrast, Ping and Pong messages are a bidirectional exchange.</t>

<t>Upon receipt of a Ping message, a single Pong message is returned with the identical
token. As with all Signaling messages, the recipient of a Ping or Pong message MUST
ignore elective options it does not understand.</t>

<t>Ping and Pong messages are indicated by the 7.02 code (Ping) and the 7.03 code (Pong).</t>

<section anchor="custody-option" title="Custody Option">

<texttable>
      <ttcol align='left'>Number</ttcol>
      <ttcol align='left'>Applies to</ttcol>
      <ttcol align='left'>Name</ttcol>
      <ttcol align='right'>Format</ttcol>
      <ttcol align='right'>Length</ttcol>
      <ttcol align='right'>Base Value</ttcol>
      <c>2</c>
      <c>Ping, Pong</c>
      <c>Custody</c>
      <c>empty</c>
      <c>0</c>
      <c>(none)</c>
</texttable>

<t>A peer replying to a Ping message can add a Custody elective option to the Pong
message it returns. This option indicates that the application has
processed all request/response messages that it has received in the
present connection ahead of the Ping message that prompted the Pong
message. (Note that there is no definition of specific application
semantics of “processed”, but there is an expectation that the sender
of the Ping leading to the Pong with a Custody Option should be able
to free buffers based on this indication.)</t>

<t>A Custody elective option can also be sent in a Ping message to explicitly
request the return of a Custody Option in the Pong message. A peer
is always free to indicate that it has finished processing
all previous request/response messages by sending a Custody Option
in a Pong message. A peer is also free NOT to send a Custody Option in case
it is still processing previous request/response messages; however,
it SHOULD delay its response to a Ping with a Custody Option until it
can also return one.</t>

</section>
</section>
<section anchor="release-messages" title="Release Messages">

<t>A release message indicates that the sender does not want to continue
maintaining the connection and opts for an orderly shutdown; the details
are in the options. A diagnostic payload MAY be included. A release message
will normally be replied to by the peer by closing the TCP/TLS connection.
Messages may be in flight when the sender decides to send a Release message.
The general expectation is that these will still be processed.</t>

<t>Release messages are indicated by the 7.04 code (Release).</t>

<t>Release messages can indicate one or more reasons using elective options.
The following options are defined:</t>

<texttable>
      <ttcol align='left'>Number</ttcol>
      <ttcol align='left'>Applies to</ttcol>
      <ttcol align='left'>Name</ttcol>
      <ttcol align='right'>Format</ttcol>
      <ttcol align='right'>Length</ttcol>
      <ttcol align='right'>Base Value</ttcol>
      <c>2</c>
      <c>Release</c>
      <c>Bad-Server-Name</c>
      <c>empty</c>
      <c>0</c>
      <c>(none)</c>
</texttable>

<t>The Bad-Server-Name elective option indicates that the default indicated
by the CSM Server-Name Option is unlikely to be useful for this server.</t>

<texttable>
      <ttcol align='left'>Number</ttcol>
      <ttcol align='left'>Applies to</ttcol>
      <ttcol align='left'>Name</ttcol>
      <ttcol align='right'>Format</ttcol>
      <ttcol align='right'>Length</ttcol>
      <ttcol align='right'>Base Value</ttcol>
      <c>4</c>
      <c>Release</c>
      <c>Alternate-Address</c>
      <c>string</c>
      <c>1-255</c>
      <c>(none)</c>
</texttable>

<t>The Alternative-Address elective option requests the peer to instead open a connection
of the same kind as the present connection to the alternative transport address given.
Its value is in the form “authority” as defined in Section 3.2 of <xref target="RFC3986"/>.</t>

<texttable>
      <ttcol align='left'>Number</ttcol>
      <ttcol align='left'>Applies to</ttcol>
      <ttcol align='left'>Name</ttcol>
      <ttcol align='right'>Format</ttcol>
      <ttcol align='right'>Length</ttcol>
      <ttcol align='right'>Base Value</ttcol>
      <c>6</c>
      <c>Release</c>
      <c>Hold-Off</c>
      <c>uint</c>
      <c>0-3</c>
      <c>(none)</c>
</texttable>

<t>The Hold-Off elective option indicates that the server is requesting that the peer not
reconnect to it for the number of seconds given in the value.</t>

</section>
<section anchor="sec-abort" title="Abort Messages">

<t>An abort message indicates that the sender is unable to continue
maintaining the connection and cannot even wait for an orderly
release. The sender shuts down the connection immediately after
the abort (and may or may not wait for a release or abort message or
connection shutdown in the inverse direction). A diagnostic payload
SHOULD be included in the Abort message. Messages may be in flight
when the sender decides to send an abort message. The general
expectation is that these will NOT be processed.</t>

<t>Abort messages are indicated by the 7.05 code (Abort).</t>

<t>Abort messages can indicate one or more reasons using elective
options. The following option is defined:</t>

<texttable>
      <ttcol align='left'>Number</ttcol>
      <ttcol align='left'>Applies to</ttcol>
      <ttcol align='left'>Name</ttcol>
      <ttcol align='right'>Format</ttcol>
      <ttcol align='right'>Length</ttcol>
      <ttcol align='right'>Base Value</ttcol>
      <c>2</c>
      <c>Abort</c>
      <c>Bad-CSM-Option</c>
      <c>uint</c>
      <c>0-2</c>
      <c>(none)</c>
</texttable>

<t>The Bad-CSM-Option Option indicates that the sender is unable to process the
CSM option identified by its option number, e.g. when it is critical
and the option number is unknown by the sender, or when there is
parameter problem with the value of an elective option. More detailed
information SHOULD be included as a diagnostic payload.</t>

<t>One reason for an sender to generate an abort message is a general
syntax error in the byte stream received. No specific option has been
defined for this, as the details of that syntax error are best left to
a diagnostic payload.</t>

</section>
<section anchor="capability-and-settings-examples" title="Capability and Settings examples">

<t>An encoded example of a Ping message with a non-empty token is shown
in <xref target="fig-ping-example"/>.</t>

<figure title="Ping Message Example" anchor="fig-ping-example"><artwork><![CDATA[
    0                   1                   2
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |      0x01     |      0xe2     |      0x42     |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

    Len   =    0 -------> 0x01
    TKL   =    1 ___/
    Code  = 7.02 Ping --> 0xe2
    Token =               0x42
]]></artwork></figure>

<t>An encoded example of the corresponding Pong message is shown in <xref target="fig-pong-example"/>.</t>

<figure title="Pong Message Example" anchor="fig-pong-example"><artwork><![CDATA[
    0                   1                   2
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |      0x01     |      0xe3     |      0x42     |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

    Len   =    0 -------> 0x01
    TKL   =    1 ___/
    Code  = 7.03 Pong --> 0xe3
    Token =               0x42
]]></artwork></figure>

</section>
</section>
<section anchor="bert" title="Block-wise Transfer and Reliable Transports">

<t>The message size restrictions defined in Section 4.6 of CoAP <xref target="RFC7252"/>
to avoid IP fragmentation are not necessary when CoAP is used over a reliable
byte stream transport. While this suggests that the Block-wise transfer protocol
<xref target="I-D.ietf-core-block"/> is also no longer needed, it remains applicable for a number of cases:</t>

<t><list style="symbols">
  <t>large messages, such as firmware downloads, may cause undesired
head-of-line blocking when a single TCP connection is used</t>
  <t>a UDP-to-TCP gateway may simply not have the context to convert a
message with a Block Option into the equivalent exchange without any
use of a Block Option (it would need to convert the entire
blockwise exchange from start to end into a single exchange)</t>
</list></t>

<t>The ‘Block-wise Extension for Reliable Transport (BERT)’ extends the
Block protocol to enable the use of larger messages over a reliable
transport.</t>

<t>The use of this new extension is signaled by sending Block1 or
Block2 Options with SZX == 7 (a “BERT option”). SZX == 7 is a 
reserved value in <xref target="I-D.ietf-core-block"/>.</t>

<t>In control usage, a BERT option is interpreted in the same way as the
equivalent Option with SZX == 6, except that it also indicates the
capability to process BERT blocks. As with the basic Block protocol,
the recipient of a CoAP request with a BERT option in control usage is
allowed to respond with a different SZX value, e.g. to send a non-BERT
block instead.</t>

<t>In descriptive usage, a BERT Option is interpreted in the same way as
the equivalent Option with SZX == 6, except that the payload is
allowed to contain a multiple of 1024 bytes (non-final BERT block) or
more than 1024 bytes (final BERT block).</t>

<t>The recipient of a non-final BERT block (M=1) conceptually partitions
the payload into a sequence of 1024-byte blocks and acts exactly as
if it had received this sequence in conjunction with block numbers
starting at, and sequentially increasing from, the block number given
in the Block Option. In other words, the entire BERT block is
positioned at the byte position that results from multiplying the
block number with 1024. The position of further blocks to be
transferred is indicated by incrementing the block number by the
number of elements in this sequence (i.e., the size of the payload
divided by 1024 bytes).</t>

<t>As with SZX == 6, the recipient of a final BERT block (M=0) simply
appends the payload at the byte position that is indicated by the
block number multiplied with 1024.</t>

<t>The following examples illustrate BERT options. A value of SZX == 7
is labeled as “BERT” or as “BERT(nnn)” to indicate a payload of size nnn.</t>

<t>In all these examples, a Block Option is decomposed to indicate the
kind of Block Option (1 or 2) followed by a colon, the block number (NUM),
more bit (M), and block size exponent (2**(SZX+4)) separated by slashes.
E.g., a Block2 Option value of 33 would be shown as 2:2/0/32), or a Block1
Option value of 59 would be shown as 1:3/1/128.</t>

<section anchor="example-get-with-bert-blocks" title="Example: GET with BERT Blocks">

<t><xref target="fig-bert1"/> shows a GET request with a response that
is split into three BERT blocks. The first response contains 3072
bytes of payload; the second, 5120; and the third, 4711. Note how
the block number increments to move the position inside the response
body forward.</t>

<figure title="GET with BERT blocks." anchor="fig-bert1"><artwork><![CDATA[
CLIENT                                       SERVER
  |                                            |
  | GET, /status                       ------> |
  |                                            |
  | <------   2.05 Content, 2:0/1/BERT(3072)   |
  |                                            |
  | GET, /status, 2:3/0/BERT           ------> |
  |                                            |
  | <------   2.05 Content, 2:3/1/BERT(5120)   |
  |                                            |
  | GET, /status, 2:8/0/BERT          ------>  |
  |                                            |
  | <------   2.05 Content, 2:8/0/BERT(4711)   |
]]></artwork></figure>

</section>
<section anchor="example-put-with-bert-blocks" title="Example: PUT with BERT Blocks">

<t><xref target="fig-bert2"/> demonstrates a PUT exchange with BERT blocks.</t>

<figure title="PUT with BERT blocks." anchor="fig-bert2"><artwork><![CDATA[
CLIENT                                        SERVER
  |                                             |
  | PUT, /options, 1:0/1/BERT(8192)     ------> |
  |                                             |
  | <------   2.31 Continue, 1:0/1/BERT         |
  |                                             |
  | PUT, /options, 1:8/1/BERT(16384)    ------> |
  |                                             |
  | <------   2.31 Continue, 1:8/1/BERT         |
  |                                             |
  | PUT, /options, 1:24/0/BERT(5683)    ------> |
  |                                             |
  | <------   2.04 Changed, 1:24/0/BERT         |
  |                                             |
]]></artwork></figure>

</section>
</section>
<section anchor="URI" title="CoAP URIs">

<t>CoAP over UDP <xref target="RFC7252"/> defines the “coap” and “coaps” URI schemes for
identifying CoAP resources and providing a means of locating the resource.</t>

<section anchor="coap-over-tcp-and-tls-uris" title="CoAP over TCP and TLS URIs">

<t>CoAP over TCP uses the “coap+tcp” URI scheme. CoAP over TLS uses the “coaps+tcp”
scheme. The rules from Section 6 of <xref target="RFC7252"/> apply to both of these URI schemes.</t>

<t><xref target="RFC7252"/>, Section 8 (Multicast CoAP) is not applicable to these schemes.</t>

<t>Resources made available via one of the “coap+tcp” or “coaps+tcp” schemes
have no shared identity with the other scheme or with the “coap” or
“coaps” scheme, even if their resource identifiers indicate the
same authority (the same host listening to the same port).
The schemes constitute distinct namespaces and, in combination with
the authority, are considered to be distinct
origin servers.</t>

<section anchor="coaptcp-uri-scheme" title="coap+tcp URI scheme">

<figure><artwork><![CDATA[
coap-tcp-URI = "coap+tcp:" "//" host [ ":" port ] path-abempty
               [ "?" query ]
]]></artwork></figure>

<t>The semantics defined in <xref target="RFC7252"/>, Section 6.1, apply to this
URI scheme, with the following changes:</t>

<t><list style="symbols">
  <t>The port subcomponent indicates the TCP port
at which the CoAP server is located. (If it is empty or not given,
then the default port 5683 is assumed, as with UDP.)</t>
</list></t>

</section>
<section anchor="coapstcp-uri-scheme" title="coaps+tcp URI scheme">

<figure><artwork><![CDATA[
coaps-tcp-URI = "coaps+tcp:" "//" host [ ":" port ] path-abempty
                [ "?" query ]
]]></artwork></figure>

<t>The semantics defined in <xref target="RFC7252"/>, Section 6.2, apply to this
URI scheme, with the following changes:</t>

<t><list style="symbols">
  <t>The port subcomponent indicates the TCP port at which the TLS server
for the CoAP server is located. If it is empty or not given, then
the default port 443 is assumed (this is different from the default
port for “coaps”, i.e., CoAP over DTLS over UDP).</t>
  <t>When CoAP is exchanged over TLS port 443, the “TLS Application
Layer Protocol Negotiation Extension” <xref target="RFC7301"/> MUST be used to allow 
demultiplexing at the server-side.</t>
</list></t>

</section>
</section>
<section anchor="uris" title="CoAP over WebSockets URIs">

<t>For the first configuration discussed in <xref target="websockets-overview"/>,
this document defines two new URIs schemes that can be used for
identifying CoAP resources and providing a means of locating these
resources: “coap+ws” and “coap+wss”.</t>

<t>Similar to the “coap” and “coaps” schemes, the “coap+ws” and
“coap+wss” schemes organize resources hierarchically under a CoAP
origin server. The key difference is that the server is potentially
reachable on a WebSocket endpoint instead of a UDP endpoint.</t>

<t>The WebSocket endpoint is identified by a “ws” or “wss” URI
that is composed of the authority part of the “coap+ws” or
“coap+wss” URI, respectively, and the well-known path
“/.well-known/coap” <xref target="RFC5785"/>.
The path and query parts of a “coap+ws” or “coap+wss” URI
identify a resource within the specified endpoint which can be
operated on by the methods defined by CoAP.</t>

<t>The syntax of the “coap+ws” and “coap+wss” URI schemes is specified
below in Augmented Backus-Naur Form (ABNF) <xref target="RFC5234"/>.
The definitions of “host”, “port”, “path-abempty” and “query” are the
same as in <xref target="RFC3986"/>.</t>

<figure><artwork align="center"><![CDATA[
coap-ws-URI =
   "coap+ws:" "//" host [ ":" port ] path-abempty [ "?" query ]

coap-wss-URI =
   "coap+wss:" "//" host [ ":" port ] path-abempty [ "?" query ]
]]></artwork></figure>

<t>The port component is OPTIONAL; the default for “coap+ws” is port
80, while the default for “coap+wss” is port 443.</t>

<t>Fragment identifiers are not part of the request URI and thus MUST
NOT be transmitted in a WebSocket handshake or in the URI options
of a CoAP request.</t>

<section anchor="decomposing-and-composing-uris" title="Decomposing and Composing URIs">

<t>The steps for decomposing a “coap+ws” or “coap+wss” URI into
CoAP options are the same as specified in Section 6.4 of <xref target="RFC7252"/>
with the following changes:</t>

<t><list style="symbols">
  <t>The &lt;scheme&gt; component MUST be “coap+ws” or “coap+wss”
when converted to ASCII lowercase.</t>
  <t>A Uri-Host Option MUST only be included in a request when
the &lt;host&gt; component does not equal the uri-host
component in the Host header field in the WebSocket
handshake.</t>
  <t>A Uri-Port Option MUST only be included in a request if
|port| does not equal the port component in the Host header
field in the WebSocket handshake.</t>
</list></t>

<t>The steps to construct a URI from a request’s options are
changed accordingly.</t>

</section>
</section>
</section>
<section anchor="security" title="Security Considerations">

<t>The security considerations of <xref target="RFC7252"/> apply.</t>

<t>Implementations of CoAP MUST use TLS version 1.2 or higher for CoAP over TLS.
The general TLS usage guidance in <xref target="RFC7525"/> SHOULD be followed.</t>

<t>Guidelines for use of cipher suites and TLS extensions can be found in <xref target="I-D.ietf-dice-profile"/>.</t>

<t>TLS does not protect the TCP header. This may, for example, 
allow an on-path adversary to terminate a TCP connection prematurely 
by spoofing a TCP reset message.</t>

<t>CoAP over WebSockets and CoAP over TLS-secured WebSockets do not
introduce additional security issues beyond CoAP and DTLS-secured CoAP
respectively <xref target="RFC7252"/>. The security considerations of <xref target="RFC6455"/> apply.</t>

<section anchor="signaling-messages" title="Signaling Messages">

<t><list style="symbols">
  <t>The guidance given by an Alternative-Address Option cannot be
followed blindly. In particular, a peer MUST NOT assume that a
successful connection to the Alternative-Address inherits all the
security properties of the current connection.</t>
  <t>SNI vs. Server-Name: Any security negotiated in the TLS handshake is
for the SNI name exchanged in the TLS handshake and checked against
the certificate provided by the server. The Server-Name Option
cannot be used to extend these security properties to the additional
server name.</t>
</list></t>

</section>
</section>
<section anchor="iana" title="IANA Considerations">

<section anchor="message-codes" title="Signaling Codes">

<t>IANA is requested to create a third sub-registry for values of the Code field in the CoAP
header (Section 12.1 of <xref target="RFC7252"/>). The name of this sub-registry is “CoAP Signaling Codes”.</t>

<t>Each entry in the sub-registry must include the Signaling Code in the range
7.01-7.31, its name, and a reference to its documentation.</t>

<t>Initial entries in this sub-registry are as follows:</t>

<texttable title="CoAP Signal Codes" anchor="signal-codes">
      <ttcol align='left'>Code</ttcol>
      <ttcol align='left'>Name</ttcol>
      <ttcol align='left'>Reference</ttcol>
      <c>7.01</c>
      <c>CSM</c>
      <c>[RFCthis]</c>
      <c>7.02</c>
      <c>Ping</c>
      <c>[RFCthis]</c>
      <c>7.03</c>
      <c>Pong</c>
      <c>[RFCthis]</c>
      <c>7.04</c>
      <c>Release</c>
      <c>[RFCthis]</c>
      <c>7.05</c>
      <c>Abort</c>
      <c>[RFCthis]</c>
</texttable>

<t>All other Signaling Codes are Unassigned.</t>

<t>The IANA policy for future additions to this sub-registry is “IETF
Review or IESG Approval” as described in <xref target="RFC5226"/>.</t>

</section>
<section anchor="option-codes" title="CoAP Signaling Option Numbers Registry">

<t>IANA is requested to create a sub-registry for signaling options similar
to the CoAP Option Numbers Registry (Section 12.2 of <xref target="RFC7252"/>), with
the single change that a fourth column is added to the sub-registry
that is one of the codes in the Signaling Codes subregistry (<xref target="message-codes"/>).</t>

<t>The name of this sub-registry is “CoAP Signaling Option Numbers”.</t>

<t>Initial entries in this sub-registry are as follows:</t>

<texttable title="CoAP Signal Option Codes" anchor="signal-option-codes">
      <ttcol align='right'>Number</ttcol>
      <ttcol align='left'>Applies to</ttcol>
      <ttcol align='left'>Name</ttcol>
      <ttcol align='center'>Reference</ttcol>
      <c>1</c>
      <c>CSM</c>
      <c>Server-Name</c>
      <c>[RFCthis]</c>
      <c>2</c>
      <c>CSM</c>
      <c>Max-Message-Size</c>
      <c>[RFCthis]</c>
      <c>4</c>
      <c>CSM</c>
      <c>Block-wise-Transfer</c>
      <c>[RFCthis]</c>
      <c>2</c>
      <c>Ping, Pong</c>
      <c>Custody</c>
      <c>[RFCthis]</c>
      <c>2</c>
      <c>Release</c>
      <c>Bad-Server-Name</c>
      <c>[RFCthis]</c>
      <c>4</c>
      <c>Release</c>
      <c>Alternative-Address</c>
      <c>[RFCthis]</c>
      <c>6</c>
      <c>Release</c>
      <c>Hold-Off</c>
      <c>[RFCthis]</c>
      <c>2</c>
      <c>Abort</c>
      <c>Bad-CSM-Option</c>
      <c>[RFCthis]</c>
</texttable>

<t>The IANA policy for future additions to this sub-registry is based on
number ranges for the option numbers, analogous to the policy defined
in Section 12.2 of <xref target="RFC7252"/>.</t>

</section>
<section anchor="service-name-and-port-number-registration" title="Service Name and Port Number Registration">

<t>IANA is requested to assign the port number 5683 and the service name “coap+tcp”,
in accordance with <xref target="RFC6335"/>.</t>

<t><list style="hanging">
  <t hangText='Service Name.'><vspace blankLines='0'/>
  coap+tcp</t>
  <t hangText='Transport Protocol.'><vspace blankLines='0'/>
  tcp</t>
  <t hangText='Assignee.'><vspace blankLines='0'/>
  IESG &lt;iesg@ietf.org&gt;</t>
  <t hangText='Contact.'><vspace blankLines='0'/>
  IETF Chair &lt;chair@ietf.org&gt;</t>
  <t hangText='Description.'><vspace blankLines='0'/>
  Constrained Application Protocol (CoAP)</t>
  <t hangText='Reference.'><vspace blankLines='0'/>
  [RFCthis]</t>
  <t hangText='Port Number.'><vspace blankLines='0'/>
  5683</t>
</list></t>

<t>Similarly, IANA is requested to assign the
service name “coaps+tcp”, in accordance with <xref target="RFC6335"/>.
However, no separate port number is used for “coaps” over TCP; instead,
the ALPN protocol ID defined in <xref target="alpnpid"/> is used over port 443.</t>

<t><list style="hanging">
  <t hangText='Service Name.'><vspace blankLines='0'/>
  coaps+tcp</t>
  <t hangText='Transport Protocol.'><vspace blankLines='0'/>
  tcp</t>
  <t hangText='Assignee.'><vspace blankLines='0'/>
  IESG &lt;iesg@ietf.org&gt;</t>
  <t hangText='Contact.'><vspace blankLines='0'/>
  IETF Chair &lt;chair@ietf.org&gt;</t>
  <t hangText='Description.'><vspace blankLines='0'/>
  Constrained Application Protocol (CoAP)</t>
  <t hangText='Reference.'><vspace blankLines='0'/>
  <xref target="RFC7301"/>, [RFCthis]</t>
  <t hangText='Port Number.'><vspace blankLines='0'/>
  443  (see also <xref target="alpnpid"/> of [RFCthis]})</t>
</list></t>

</section>
<section anchor="uri-scheme-registration" title="URI Scheme Registration">

<t>This document registers two new URI schemes, namely “coap+tcp” and
“coaps+tcp”, for the use of CoAP over TCP and for CoAP over TLS over
TCP, respectively. The “coap+tcp” and “coaps+tcp” URI schemes can thus
be compared to the “http” and “https” URI schemes.</t>

<t>The syntax of the “coap” and “coaps” URI schemes is specified in
Section 6 of <xref target="RFC7252"/> and the present document re-uses their
semantics for “coap+tcp” and “coaps+tcp”, respectively, with the
exception that TCP, or TLS over TCP is used as a transport protocol.</t>

<t>IANA is requested to add these new URI schemes to the registry
established with <xref target="RFC7595"/>.</t>

<section anchor="coapws" title="coap+ws">

<t>This document requests the registration of the Uniform Resource
Identifier (URI) scheme “coap+ws”. The registration request complies
with <xref target="RFC4395"/>.</t>

<t><list style="hanging">
  <t hangText='URL scheme name.'><vspace blankLines='0'/>
  coap+ws</t>
  <t hangText='Status.'><vspace blankLines='0'/>
  Permanent</t>
  <t hangText='URI scheme syntax.'><vspace blankLines='0'/>
  Defined in Section N of [RFCthis]</t>
  <t hangText='URI scheme semantics.'><vspace blankLines='0'/>
  The “coap+ws” URI scheme provides a way to identify resources that
are potentially accessible over the Constrained Application Protocol (CoAP)
using the WebSocket protocol.</t>
  <t hangText='Encoding considerations.'><vspace blankLines='0'/>
  The scheme encoding conforms to the encoding rules established for URIs
in <xref target="RFC3986"/>, i.e., internationalized and reserved characters are expressed
using UTF-8-based percent-encoding.</t>
  <t hangText='Applications/protocols that use this URI scheme name.'><vspace blankLines='0'/>
  The scheme is used by CoAP endpoints to access CoAP resources using the WebSocket protocol.</t>
  <t hangText='Interoperability considerations.'><vspace blankLines='0'/>
  None.</t>
  <t hangText='Security Considerations.'><vspace blankLines='0'/>
  See Section N of [RFCthis]</t>
  <t hangText='Contact.'><vspace blankLines='0'/>
  IETF chair &lt;chair@ietf.org&gt;</t>
  <t hangText='Author/Change controller.'><vspace blankLines='0'/>
  IESG &lt;iesg@ietf.org&gt;</t>
  <t hangText='References.'><vspace blankLines='0'/>
  [RFCthis]</t>
</list></t>

</section>
<section anchor="coapwss" title="coap+wss">
<t>This document requests the registration of the Uniform Resource
Identifier (URI) scheme “coap+wss”. The registration request complies
with <xref target="RFC4395"/>.</t>

<t><list style="hanging">
  <t hangText='URL scheme name.'><vspace blankLines='0'/>
  coap+wss</t>
  <t hangText='Status.'><vspace blankLines='0'/>
  Permanent</t>
  <t hangText='URI scheme syntax.'><vspace blankLines='0'/>
  Defined in Section N of [RFCthis]</t>
  <t hangText='URI scheme semantics.'><vspace blankLines='0'/>
  The “coap+ws” URI scheme provides a way to identify resources that
are potentially accessible over the Constrained Application Protocol (CoAP)
using the WebSocket protocol secured with Transport Layer Security (TLS).</t>
  <t hangText='Encoding considerations.'><vspace blankLines='0'/>
  The scheme encoding conforms to the encoding rules established for URIs
in <xref target="RFC3986"/>, i.e., internationalized and reserved characters are expressed
using UTF-8-based percent-encoding.</t>
  <t hangText='Applications/protocols that use this URI scheme name.'><vspace blankLines='0'/>
  The scheme is used by CoAP endpoints to access CoAP resources using the WebSocket protocol
secured with TLS.</t>
  <t hangText='Interoperability considerations.'><vspace blankLines='0'/>
  None.</t>
  <t hangText='Security Considerations.'><vspace blankLines='0'/>
  See Section N of [RFCthis]</t>
  <t hangText='Contact.'><vspace blankLines='0'/>
  IETF chair &lt;chair@ietf.org&gt;</t>
  <t hangText='Author/Change controller.'><vspace blankLines='0'/>
  IESG &lt;iesg@ietf.org&gt;</t>
  <t hangText='References.'><vspace blankLines='0'/>
  [RFCthis]</t>
</list></t>

</section>
</section>
<section anchor="well-known-uri-suffix-registration" title="Well-Known URI Suffix Registration">

<t>IANA is requested to register the ‘coap’ well-known URI in the “Well-Known URIs” registry. This
registration request complies with <xref target="RFC5785"/>:</t>

<t><list style="hanging">
  <t hangText='URI Suffix.'><vspace blankLines='0'/>
  coap</t>
  <t hangText='Change controller.'><vspace blankLines='0'/>
  IETF</t>
  <t hangText='Specification document(s).'><vspace blankLines='0'/>
  [RFCthis]</t>
  <t hangText='Related information.'><vspace blankLines='0'/>
  None.</t>
</list></t>

</section>
<section anchor="alpnpid" title="ALPN Protocol ID">

<t>IANA is requested to assign the following value in the registry
“Application Layer Protocol Negotiation (ALPN) Protocol IDs” created
by <xref target="RFC7301"/>:</t>

<t><list style="hanging">
  <t hangText='Protocol.'><vspace blankLines='0'/>
  CoAP</t>
  <t hangText='Identification Sequence.'><vspace blankLines='0'/>
  0x63 0x6f 0x61 0x70 (“coap”)</t>
  <t hangText='Reference.'><vspace blankLines='0'/>
  [RFCthis]</t>
</list></t>

</section>
<section anchor="websocket-subprotocol-registration" title="WebSocket Subprotocol Registration">

<t>IANA is requested to register the WebSocket CoAP subprotocol under the “WebSocket Subprotocol Name Registry”:</t>

<t><list style="hanging">
  <t hangText='Subprotocol Identifier.'><vspace blankLines='0'/>
  coap</t>
  <t hangText='Subprotocol Common Name.'><vspace blankLines='0'/>
  Constrained Application Protocol (CoAP)</t>
  <t hangText='Subprotocol Definition.'><vspace blankLines='0'/>
  [RFCthis]</t>
</list></t>

</section>
</section>


  </middle>

  <back>

    <references title='Normative References'>





<reference  anchor='RFC0793' target='http://www.rfc-editor.org/info/rfc793'>
<front>
<title>Transmission Control Protocol</title>
<author initials='J.' surname='Postel' fullname='J. Postel'><organization /></author>
<date year='1981' month='September' />
</front>
<seriesInfo name='STD' value='7'/>
<seriesInfo name='RFC' value='793'/>
<seriesInfo name='DOI' value='10.17487/RFC0793'/>
</reference>



<reference  anchor='RFC2119' target='http://www.rfc-editor.org/info/rfc2119'>
<front>
<title>Key words for use in RFCs to Indicate Requirement Levels</title>
<author initials='S.' surname='Bradner' fullname='S. Bradner'><organization /></author>
<date year='1997' month='March' />
<abstract><t>In many standards track documents several words are used to signify the requirements in the specification.  These words are often capitalized. This document defines these words as they should be interpreted in IETF documents.  This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.</t></abstract>
</front>
<seriesInfo name='BCP' value='14'/>
<seriesInfo name='RFC' value='2119'/>
<seriesInfo name='DOI' value='10.17487/RFC2119'/>
</reference>



<reference  anchor='RFC3986' target='http://www.rfc-editor.org/info/rfc3986'>
<front>
<title>Uniform Resource Identifier (URI): Generic Syntax</title>
<author initials='T.' surname='Berners-Lee' fullname='T. Berners-Lee'><organization /></author>
<author initials='R.' surname='Fielding' fullname='R. Fielding'><organization /></author>
<author initials='L.' surname='Masinter' fullname='L. Masinter'><organization /></author>
<date year='2005' month='January' />
<abstract><t>A Uniform Resource Identifier (URI) is a compact sequence of characters that identifies an abstract or physical resource.  This specification defines the generic URI syntax and a process for resolving URI references that might be in relative form, along with guidelines and security considerations for the use of URIs on the Internet.  The URI syntax defines a grammar that is a superset of all valid URIs, allowing an implementation to parse the common components of a URI reference without knowing the scheme-specific requirements of every possible identifier.  This specification does not define a generative grammar for URIs; that task is performed by the individual specifications of each URI scheme.  [STANDARDS-TRACK]</t></abstract>
</front>
<seriesInfo name='STD' value='66'/>
<seriesInfo name='RFC' value='3986'/>
<seriesInfo name='DOI' value='10.17487/RFC3986'/>
</reference>



<reference  anchor='RFC4395' target='http://www.rfc-editor.org/info/rfc4395'>
<front>
<title>Guidelines and Registration Procedures for New URI Schemes</title>
<author initials='T.' surname='Hansen' fullname='T. Hansen'><organization /></author>
<author initials='T.' surname='Hardie' fullname='T. Hardie'><organization /></author>
<author initials='L.' surname='Masinter' fullname='L. Masinter'><organization /></author>
<date year='2006' month='February' />
<abstract><t>This document provides guidelines and recommendations for the definition of Uniform Resource Identifier (URI) schemes.  It also updates the process and IANA registry for URI schemes.  It obsoletes both RFC 2717 and RFC 2718.  This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.</t></abstract>
</front>
<seriesInfo name='RFC' value='4395'/>
<seriesInfo name='DOI' value='10.17487/RFC4395'/>
</reference>



<reference  anchor='RFC5226' target='http://www.rfc-editor.org/info/rfc5226'>
<front>
<title>Guidelines for Writing an IANA Considerations Section in RFCs</title>
<author initials='T.' surname='Narten' fullname='T. Narten'><organization /></author>
<author initials='H.' surname='Alvestrand' fullname='H. Alvestrand'><organization /></author>
<date year='2008' month='May' />
<abstract><t>Many protocols make use of identifiers consisting of constants and other well-known values.  Even after a protocol has been defined and deployment has begun, new values may need to be assigned (e.g., for a new option type in DHCP, or a new encryption or authentication transform for IPsec).  To ensure that such quantities have consistent values and interpretations across all implementations, their assignment must be administered by a central authority.  For IETF protocols, that role is provided by the Internet Assigned Numbers Authority (IANA).</t><t>In order for IANA to manage a given namespace prudently, it needs guidelines describing the conditions under which new values can be assigned or when modifications to existing values can be made.  If IANA is expected to play a role in the management of a namespace, IANA must be given clear and concise instructions describing that role.  This document discusses issues that should be considered in formulating a policy for assigning values to a namespace and provides guidelines for authors on the specific text that must be included in documents that place demands on IANA.</t><t>This document obsoletes RFC 2434.  This document specifies an Internet Best  Current Practices for the Internet Community, and requests discussion and  suggestions for improvements.</t></abstract>
</front>
<seriesInfo name='BCP' value='26'/>
<seriesInfo name='RFC' value='5226'/>
<seriesInfo name='DOI' value='10.17487/RFC5226'/>
</reference>



<reference  anchor='RFC5246' target='http://www.rfc-editor.org/info/rfc5246'>
<front>
<title>The Transport Layer Security (TLS) Protocol Version 1.2</title>
<author initials='T.' surname='Dierks' fullname='T. Dierks'><organization /></author>
<author initials='E.' surname='Rescorla' fullname='E. Rescorla'><organization /></author>
<date year='2008' month='August' />
<abstract><t>This document specifies Version 1.2 of the Transport Layer Security (TLS) protocol.  The TLS protocol provides communications security over the Internet.  The protocol allows client/server applications to communicate in a way that is designed to prevent eavesdropping, tampering, or message forgery.  [STANDARDS-TRACK]</t></abstract>
</front>
<seriesInfo name='RFC' value='5246'/>
<seriesInfo name='DOI' value='10.17487/RFC5246'/>
</reference>



<reference  anchor='RFC5785' target='http://www.rfc-editor.org/info/rfc5785'>
<front>
<title>Defining Well-Known Uniform Resource Identifiers (URIs)</title>
<author initials='M.' surname='Nottingham' fullname='M. Nottingham'><organization /></author>
<author initials='E.' surname='Hammer-Lahav' fullname='E. Hammer-Lahav'><organization /></author>
<date year='2010' month='April' />
<abstract><t>This memo defines a path prefix for &quot;well-known locations&quot;, &quot;/.well-known/&quot;, in selected Uniform Resource Identifier (URI) schemes.   [STANDARDS-TRACK]</t></abstract>
</front>
<seriesInfo name='RFC' value='5785'/>
<seriesInfo name='DOI' value='10.17487/RFC5785'/>
</reference>



<reference  anchor='RFC6455' target='http://www.rfc-editor.org/info/rfc6455'>
<front>
<title>The WebSocket Protocol</title>
<author initials='I.' surname='Fette' fullname='I. Fette'><organization /></author>
<author initials='A.' surname='Melnikov' fullname='A. Melnikov'><organization /></author>
<date year='2011' month='December' />
<abstract><t>The WebSocket Protocol enables two-way communication between a client running untrusted code in a controlled environment to a remote host that has opted-in to communications from that code.  The security model used for this is the origin-based security model commonly used by web browsers.  The protocol consists of an opening handshake followed by basic message framing, layered over TCP.  The goal of this technology is to provide a mechanism for browser-based applications that need two-way communication with servers that does not rely on opening multiple HTTP connections (e.g., using XMLHttpRequest or &lt;iframe&gt;s and long polling).  [STANDARDS-TRACK]</t></abstract>
</front>
<seriesInfo name='RFC' value='6455'/>
<seriesInfo name='DOI' value='10.17487/RFC6455'/>
</reference>



<reference  anchor='RFC7252' target='http://www.rfc-editor.org/info/rfc7252'>
<front>
<title>The Constrained Application Protocol (CoAP)</title>
<author initials='Z.' surname='Shelby' fullname='Z. Shelby'><organization /></author>
<author initials='K.' surname='Hartke' fullname='K. Hartke'><organization /></author>
<author initials='C.' surname='Bormann' fullname='C. Bormann'><organization /></author>
<date year='2014' month='June' />
<abstract><t>The Constrained Application Protocol (CoAP) is a specialized web transfer protocol for use with constrained nodes and constrained (e.g., low-power, lossy) networks.  The nodes often have 8-bit microcontrollers with small amounts of ROM and RAM, while constrained networks such as IPv6 over Low-Power Wireless Personal Area Networks (6LoWPANs) often have high packet error rates and a typical throughput of 10s of kbit/s.  The protocol is designed for machine- to-machine (M2M) applications such as smart energy and building automation.</t><t>CoAP provides a request/response interaction model between application endpoints, supports built-in discovery of services and resources, and includes key concepts of the Web such as URIs and Internet media types.  CoAP is designed to easily interface with HTTP for integration with the Web while meeting specialized requirements such as multicast support, very low overhead, and simplicity for constrained environments.</t></abstract>
</front>
<seriesInfo name='RFC' value='7252'/>
<seriesInfo name='DOI' value='10.17487/RFC7252'/>
</reference>



<reference  anchor='RFC7301' target='http://www.rfc-editor.org/info/rfc7301'>
<front>
<title>Transport Layer Security (TLS) Application-Layer Protocol Negotiation Extension</title>
<author initials='S.' surname='Friedl' fullname='S. Friedl'><organization /></author>
<author initials='A.' surname='Popov' fullname='A. Popov'><organization /></author>
<author initials='A.' surname='Langley' fullname='A. Langley'><organization /></author>
<author initials='E.' surname='Stephan' fullname='E. Stephan'><organization /></author>
<date year='2014' month='July' />
<abstract><t>This document describes a Transport Layer Security (TLS) extension for application-layer protocol negotiation within the TLS handshake. For instances in which multiple application protocols are supported on the same TCP or UDP port, this extension allows the application layer to negotiate which protocol will be used within the TLS connection.</t></abstract>
</front>
<seriesInfo name='RFC' value='7301'/>
<seriesInfo name='DOI' value='10.17487/RFC7301'/>
</reference>



<reference  anchor='RFC7525' target='http://www.rfc-editor.org/info/rfc7525'>
<front>
<title>Recommendations for Secure Use of Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS)</title>
<author initials='Y.' surname='Sheffer' fullname='Y. Sheffer'><organization /></author>
<author initials='R.' surname='Holz' fullname='R. Holz'><organization /></author>
<author initials='P.' surname='Saint-Andre' fullname='P. Saint-Andre'><organization /></author>
<date year='2015' month='May' />
<abstract><t>Transport Layer Security (TLS) and Datagram Transport Layer Security (DTLS) are widely used to protect data exchanged over application protocols such as HTTP, SMTP, IMAP, POP, SIP, and XMPP.  Over the last few years, several serious attacks on TLS have emerged, including attacks on its most commonly used cipher suites and their modes of operation.  This document provides recommendations for improving the security of deployed services that use TLS and DTLS. The recommendations are applicable to the majority of use cases.</t></abstract>
</front>
<seriesInfo name='BCP' value='195'/>
<seriesInfo name='RFC' value='7525'/>
<seriesInfo name='DOI' value='10.17487/RFC7525'/>
</reference>



<reference  anchor='RFC7595' target='http://www.rfc-editor.org/info/rfc7595'>
<front>
<title>Guidelines and Registration Procedures for URI Schemes</title>
<author initials='D.' surname='Thaler' fullname='D. Thaler' role='editor'><organization /></author>
<author initials='T.' surname='Hansen' fullname='T. Hansen'><organization /></author>
<author initials='T.' surname='Hardie' fullname='T. Hardie'><organization /></author>
<date year='2015' month='June' />
<abstract><t>This document updates the guidelines and recommendations, as well as the IANA registration processes, for the definition of Uniform Resource Identifier (URI) schemes.  It obsoletes RFC 4395.</t></abstract>
</front>
<seriesInfo name='BCP' value='35'/>
<seriesInfo name='RFC' value='7595'/>
<seriesInfo name='DOI' value='10.17487/RFC7595'/>
</reference>



<reference  anchor='RFC7641' target='http://www.rfc-editor.org/info/rfc7641'>
<front>
<title>Observing Resources in the Constrained Application Protocol (CoAP)</title>
<author initials='K.' surname='Hartke' fullname='K. Hartke'><organization /></author>
<date year='2015' month='September' />
<abstract><t>The Constrained Application Protocol (CoAP) is a RESTful application protocol for constrained nodes and networks.  The state of a resource on a CoAP server can change over time.  This document specifies a simple protocol extension for CoAP that enables CoAP clients to &quot;observe&quot; resources, i.e., to retrieve a representation of a resource and keep this representation updated by the server over a period of time.  The protocol follows a best-effort approach for sending new representations to clients and provides eventual consistency between the state observed by each client and the actual resource state at the server.</t></abstract>
</front>
<seriesInfo name='RFC' value='7641'/>
<seriesInfo name='DOI' value='10.17487/RFC7641'/>
</reference>



<reference anchor='I-D.ietf-dice-profile'>
<front>
<title>TLS/DTLS Profiles for the Internet of Things</title>

<author initials='H' surname='Tschofenig' fullname='Hannes Tschofenig'>
    <organization />
</author>

<author initials='T' surname='Fossati' fullname='Thomas Fossati'>
    <organization />
</author>

<date month='October' day='18' year='2015' />

<abstract><t>A common design pattern in Internet of Things (IoT) deployments is the use of a constrained device that collects data via sensors or controls actuators for use in home automation, industrial control systems, smart cities and other IoT deployments.  This document defines a Transport Layer Security (TLS) and Datagram TLS (DTLS) 1.2 profile that offers communications security for this data exchange thereby preventing eavesdropping, tampering, and message forgery.  The lack of communication security is a common vulnerability in Internet of Things products that can easily be solved by using these well-researched and widely deployed Internet security protocols.</t></abstract>

</front>

<seriesInfo name='Internet-Draft' value='draft-ietf-dice-profile-17' />
<format type='TXT'
        target='http://www.ietf.org/internet-drafts/draft-ietf-dice-profile-17.txt' />
</reference>




    </references>

    <references title='Informative References'>





<reference anchor='I-D.ietf-core-block'>
<front>
<title>Block-wise transfers in CoAP</title>

<author initials='C' surname='Bormann' fullname='Carsten Bormann'>
    <organization />
</author>

<author initials='Z' surname='Shelby' fullname='Zach Shelby'>
    <organization />
</author>

<date month='April' day='29' year='2016' />

<abstract><t>CoAP is a RESTful transfer protocol for constrained nodes and networks.  Basic CoAP messages work well for the small payloads we expect from temperature sensors, light switches, and similar building-automation devices.  Occasionally, however, applications will need to transfer larger payloads -- for instance, for firmware updates.  With HTTP, TCP does the grunt work of slicing large payloads up into multiple packets and ensuring that they all arrive and are handled in the right order.  CoAP is based on datagram transports such as UDP or DTLS, which limits the maximum size of resource representations that can be transferred without too much fragmentation.  Although UDP supports larger payloads through IP fragmentation, it is limited to 64 KiB and, more importantly, doesn't really work well for constrained applications and networks.  Instead of relying on IP fragmentation, this specification extends basic CoAP with a pair of "Block" options, for transferring multiple blocks of information from a resource representation in multiple request-response pairs.  In many important cases, the Block options enable a server to be truly stateless: the server can handle each block transfer separately, with no need for a connection setup or other server-side memory of previous block transfers.  In summary, the Block options provide a minimal way to transfer larger representations in a block-wise fashion.</t></abstract>

</front>

<seriesInfo name='Internet-Draft' value='draft-ietf-core-block-20' />
<format type='TXT'
        target='http://www.ietf.org/internet-drafts/draft-ietf-core-block-20.txt' />
</reference>



<reference anchor='I-D.becker-core-coap-sms-gprs'>
<front>
<title>Transport of CoAP over SMS</title>

<author initials='M' surname='Becker' fullname='Markus Becker'>
    <organization />
</author>

<author initials='K' surname='Li' fullname='Kepeng Li'>
    <organization />
</author>

<author initials='K' surname='Kuladinithi' fullname='Koojana Kuladinithi'>
    <organization />
</author>

<author initials='T' surname='Poetsch' fullname='Thomas Poetsch'>
    <organization />
</author>

<date month='August' day='8' year='2014' />

<abstract><t>Short Message Service (SMS) of mobile cellular networks is frequently used in Machine-To-Machine (M2M) communications, such as for telematic devices.  The service offers small packet sizes and high delays just as other typical low-power and lossy networks (LLNs), i.e. 6LoWPANs.  The design of the Constrained Application Protocol (CoAP) [RFC7252], that took the limitations of LLNs into account, is thus also applicable to other transports.  The adaptation of CoAP to SMS transport mechanisms is described in this document.</t></abstract>

</front>

<seriesInfo name='Internet-Draft' value='draft-becker-core-coap-sms-gprs-05' />
<format type='TXT'
        target='http://www.ietf.org/internet-drafts/draft-becker-core-coap-sms-gprs-05.txt' />
</reference>



<reference  anchor='RFC0768' target='http://www.rfc-editor.org/info/rfc768'>
<front>
<title>User Datagram Protocol</title>
<author initials='J.' surname='Postel' fullname='J. Postel'><organization /></author>
<date year='1980' month='August' />
</front>
<seriesInfo name='STD' value='6'/>
<seriesInfo name='RFC' value='768'/>
<seriesInfo name='DOI' value='10.17487/RFC0768'/>
</reference>



<reference  anchor='RFC5234' target='http://www.rfc-editor.org/info/rfc5234'>
<front>
<title>Augmented BNF for Syntax Specifications: ABNF</title>
<author initials='D.' surname='Crocker' fullname='D. Crocker' role='editor'><organization /></author>
<author initials='P.' surname='Overell' fullname='P. Overell'><organization /></author>
<date year='2008' month='January' />
<abstract><t>Internet technical specifications often need to define a formal syntax.  Over the years, a modified version of Backus-Naur Form (BNF), called Augmented BNF (ABNF), has been popular among many Internet specifications.  The current specification documents ABNF. It balances compactness and simplicity with reasonable representational power.  The differences between standard BNF and ABNF involve naming rules, repetition, alternatives, order-independence, and value ranges.  This specification also supplies additional rule definitions and encoding for a core lexical analyzer of the type common to several Internet specifications.  [STANDARDS-TRACK]</t></abstract>
</front>
<seriesInfo name='STD' value='68'/>
<seriesInfo name='RFC' value='5234'/>
<seriesInfo name='DOI' value='10.17487/RFC5234'/>
</reference>



<reference  anchor='RFC6454' target='http://www.rfc-editor.org/info/rfc6454'>
<front>
<title>The Web Origin Concept</title>
<author initials='A.' surname='Barth' fullname='A. Barth'><organization /></author>
<date year='2011' month='December' />
<abstract><t>This document defines the concept of an &quot;origin&quot;, which is often used as the scope of authority or privilege by user agents.  Typically, user agents isolate content retrieved from different origins to prevent malicious web site operators from interfering with the operation of benign web sites.  In addition to outlining the principles that underlie the concept of origin, this document details how to determine the origin of a URI and how to serialize an origin into a string.  It also defines an HTTP header field, named &quot;Origin&quot;, that indicates which origins are associated with an HTTP request.   [STANDARDS-TRACK]</t></abstract>
</front>
<seriesInfo name='RFC' value='6454'/>
<seriesInfo name='DOI' value='10.17487/RFC6454'/>
</reference>



<reference  anchor='RFC6335' target='http://www.rfc-editor.org/info/rfc6335'>
<front>
<title>Internet Assigned Numbers Authority (IANA) Procedures for the Management of the Service Name and Transport Protocol Port Number Registry</title>
<author initials='M.' surname='Cotton' fullname='M. Cotton'><organization /></author>
<author initials='L.' surname='Eggert' fullname='L. Eggert'><organization /></author>
<author initials='J.' surname='Touch' fullname='J. Touch'><organization /></author>
<author initials='M.' surname='Westerlund' fullname='M. Westerlund'><organization /></author>
<author initials='S.' surname='Cheshire' fullname='S. Cheshire'><organization /></author>
<date year='2011' month='August' />
<abstract><t>This document defines the procedures that the Internet Assigned Numbers Authority (IANA) uses when handling assignment and other requests related to the Service Name and Transport Protocol Port Number registry.  It also discusses the rationale and principles behind these procedures and how they facilitate the long-term sustainability of the registry.</t><t>This document updates IANA's procedures by obsoleting the previous UDP and TCP port assignment procedures defined in Sections 8 and 9.1 of the IANA Allocation Guidelines, and it updates the IANA service name and port assignment procedures for UDP-Lite, the Datagram Congestion Control Protocol (DCCP), and the Stream Control Transmission Protocol (SCTP).  It also updates the DNS SRV specification to clarify what a service name is and how it is registered.  This memo documents an Internet Best Current Practice.</t></abstract>
</front>
<seriesInfo name='BCP' value='165'/>
<seriesInfo name='RFC' value='6335'/>
<seriesInfo name='DOI' value='10.17487/RFC6335'/>
</reference>



<reference  anchor='RFC6347' target='http://www.rfc-editor.org/info/rfc6347'>
<front>
<title>Datagram Transport Layer Security Version 1.2</title>
<author initials='E.' surname='Rescorla' fullname='E. Rescorla'><organization /></author>
<author initials='N.' surname='Modadugu' fullname='N. Modadugu'><organization /></author>
<date year='2012' month='January' />
<abstract><t>This document specifies version 1.2 of the Datagram Transport Layer Security (DTLS) protocol.  The DTLS protocol provides communications privacy for datagram protocols.  The protocol allows client/server applications to communicate in a way that is designed to prevent eavesdropping, tampering, or message forgery.  The DTLS protocol is based on the Transport Layer Security (TLS) protocol and provides equivalent security guarantees.  Datagram semantics of the underlying transport are preserved by the DTLS protocol.  This document updates DTLS 1.0 to work with TLS version 1.2.  [STANDARDS-TRACK]</t></abstract>
</front>
<seriesInfo name='RFC' value='6347'/>
<seriesInfo name='DOI' value='10.17487/RFC6347'/>
</reference>



<reference  anchor='RFC7230' target='http://www.rfc-editor.org/info/rfc7230'>
<front>
<title>Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing</title>
<author initials='R.' surname='Fielding' fullname='R. Fielding' role='editor'><organization /></author>
<author initials='J.' surname='Reschke' fullname='J. Reschke' role='editor'><organization /></author>
<date year='2014' month='June' />
<abstract><t>The Hypertext Transfer Protocol (HTTP) is a stateless application-level protocol for distributed, collaborative, hypertext information systems.  This document provides an overview of HTTP architecture and its associated terminology, defines the &quot;http&quot; and &quot;https&quot; Uniform Resource Identifier (URI) schemes, defines the HTTP/1.1 message syntax and parsing requirements, and describes related security concerns for implementations.</t></abstract>
</front>
<seriesInfo name='RFC' value='7230'/>
<seriesInfo name='DOI' value='10.17487/RFC7230'/>
</reference>


<reference anchor="HomeGateway" >
  <front>
    <title>An experimental study of home gateway characteristics</title>
    <author initials="L." surname="Eggert" fullname="Lars Eggert">
      <organization></organization>
    </author>
    <date year="2010"/>
  </front>
  <seriesInfo name="Proceedings" value="of the 10th annual conference on Internet measurement"/>
</reference>


    </references>


<section anchor="negotiation" title="Negotiating Protocol Versions">

<t>CoAP is defined in <xref target="RFC7252"/> with a version number of 1. At this time,
there is no known reason to support version numbers different from 1.</t>

<t>In contrast to the message layer for UDP and DTLS, the CoAP over TCP
message format does not include a version number. If version negotiation
needs to be addressed in the future, then Capability and Settings have been
specifically designed to enable such a potential feature.</t>

</section>
<section anchor="examples" title="CoAP over WebSocket Examples">

<t>This section gives examples for the first two configurations
discussed in <xref target="websockets-overview"/>.</t>

<t>An example of the process followed by a CoAP client to retrieve the
representation of a resource identified by a “coap+ws” URI might be as
follows. <xref target="example-1"/> below illustrates the WebSocket and
CoAP messages exchanged in detail.</t>

<t><list style="numbers">
  <t>The CoAP client obtains the URI
  &lt;coap+ws://example.org/sensors/temperature?u=Cel&gt;,
  for example, from a resource representation that it retrieved
  previously.</t>
  <t>It establishes a WebSocket connection to the endpoint URI composed
  of the authority “example.org” and the well-known path
  “/.well-known/coap”, &lt;ws://example.org/.well-known/coap&gt;.</t>
  <t>It sends a single-frame, masked, binary message containing a CoAP
  request. The request indicates the target resource with the
  Uri-Path (“sensors”, “temperature”) and Uri-Query (“u=Cel”)
  options.</t>
  <t>It waits for the server to return a response.</t>
  <t>The CoAP client uses the connection for further requests, or the
  connection is closed.</t>
</list></t>

<figure title="A CoAP client retrieves the representation of a resource identified by a &quot;coap+ws&quot; URI" anchor="example-1"><artwork><![CDATA[
   CoAP        CoAP
  Client      Server
(WebSocket  (WebSocket
  Client)     Server)

     |          |
     |          |
     +=========>|  GET /.well-known/coap HTTP/1.1
     |          |  Host: example.org
     |          |  Upgrade: websocket
     |          |  Connection: Upgrade
     |          |  Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
     |          |  Sec-WebSocket-Protocol: coap
     |          |  Sec-WebSocket-Version: 13
     |          |
     |<=========+  HTTP/1.1 101 Switching Protocols
     |          |  Upgrade: websocket
     |          |  Connection: Upgrade
     |          |  Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
     |          |  Sec-WebSocket-Protocol: coap
     |          |
     |          |
     +--------->|  Binary frame (opcode=%x2, FIN=1, MASK=1)
     |          |    +-------------------------+
     |          |    | GET                     |
     |          |    | Token: 0x53             |
     |          |    | Uri-Path: "sensors"     |
     |          |    | Uri-Path: "temperature" |
     |          |    | Uri-Query: "u=Cel"      |
     |          |    +-------------------------+
     |          |
     |<---------+  Binary frame (opcode=%x2, FIN=1, MASK=0)
     |          |    +-------------------------+
     |          |    | 2.05 Content            |
     |          |    | Token: 0x53             |
     |          |    | Payload: "22.3 Cel"     |
     |          |    +-------------------------+
     :          :
     :          :
     |          |
     +--------->|  Close frame (opcode=%x8, FIN=1, MASK=1)
     |          |
     |<---------+  Close frame (opcode=%x8, FIN=1, MASK=0)
     |          |
]]></artwork></figure>

<t><xref target="example-2"/> shows how a CoAP client uses a CoAP
forward proxy with a WebSocket endpoint to retrieve the representation
of the resource “coap://[2001:DB8::1]/”. The use of the forward
proxy and the address of the WebSocket endpoint are determined by the
client from local configuration rules. The request URI is specified
in the Proxy-Uri Option. Since the request URI uses the “coap” URI
scheme, the proxy fulfills the request by issuing a Confirmable GET
request over UDP to the CoAP server and returning the response over
the WebSocket connection to the client.</t>

<figure title="A CoAP client retrieves the representation of a resource identified by a &quot;coap&quot; URI via a WebSockets-enabled CoAP proxy" anchor="example-2"><artwork><![CDATA[
   CoAP        CoAP       CoAP
  Client      Proxy      Server
(WebSocket  (WebSocket    (UDP
  Client)     Server)   Endpoint)

     |          |          |
     +--------->|          |  Binary frame (opcode=%x2, FIN=1, MASK=1)
     |          |          |    +------------------------------------+
     |          |          |    | GET                                |
     |          |          |    | Token: 0x7d                        |
     |          |          |    | Proxy-Uri: "coap://[2001:DB8::1]/" |
     |          |          |    +------------------------------------+
     |          |          |
     |          +--------->|  CoAP message (Ver=1, T=Con, MID=0x8f54)
     |          |          |    +------------------------------------+
     |          |          |    | GET                                |
     |          |          |    | Token: 0x0a15                      |
     |          |          |    +------------------------------------+
     |          |          |
     |          |<---------+  CoAP message (Ver=1, T=Ack, MID=0x8f54)
     |          |          |    +------------------------------------+
     |          |          |    | 2.05 Content                       |
     |          |          |    | Token: 0x0a15                      |
     |          |          |    | Payload: "ready"                   |
     |          |          |    +------------------------------------+
     |          |          |
     |<---------+          |  Binary frame (opcode=%x2, FIN=1, MASK=0)
     |          |          |    +------------------------------------+
     |          |          |    | 2.05 Content                       |
     |          |          |    | Token: 0x7d                        |
     |          |          |    | Payload: "ready"                   |
     |          |          |    +------------------------------------+
     |          |          |
]]></artwork></figure>

</section>
<section anchor="change-log" title="Change Log">

<t>The RFC Editor is requested to remove this section at publication.</t>

<section anchor="since-draft-core-coap-tcp-tls-02" title="Since draft-core-coap-tcp-tls-02">

<t>Merged draft-savolainen-core-coap-websockets-07
Merged draft-bormann-core-block-bert-01
Merged draft-bormann-core-coap-sig-02</t>

</section>
</section>
<section numbered="no" anchor="acknowledgements" title="Acknowledgements">

<t>We would like to thank Stephen Berard, Geoffrey Cristallo, 
Olivier Delaby, Christian Groves, Nadir Javed,
Michael Koster, Matthias Kovatsch, Achim Kraus, David Navarro,
Szymon Sasin, Zach Shelby, Andrew Summers, Julien Vermillard, 
and Gengyu Wei for their feedback.</t>

</section>
<section numbered="no" anchor="contributors" title="Contributors">

<figure><artwork><![CDATA[
Valik Solorzano Barboza
Zebra Technologies
820 W. Jackson Blvd. Suite 700
Chicago 60607
United States of America

Phone: +1-847-634-6700
Email: vsolorzanobarboza@zebra.com

Teemu Savolainen
Nokia Technologies
Hatanpaan valtatie 30
Tampere FI-33100
Finland

Email: teemu.savolainen@nokia.com
]]></artwork></figure>

<!--  LocalWords:  TCP CoAP UDP firewalling firewalled TLS IP SCTP
 -->
<!--  LocalWords:  DCCP IoT optimizations ACKs acknowledgement TKL
 -->
<!--  LocalWords:  prepending URI DTLS demultiplexing demultiplex pre
 -->
<!--  LocalWords:  IANA ALPN Middleboxes NATs ACK acknowledgements
 -->
<!--  LocalWords:  datagram prepended CBOR namespaces subcomponent
 -->
<!--  LocalWords:  Assignee Confirmable untyped
 -->

</section>


  </back>
</rfc>

