Specification
The core of the protocol is specified in . Various extensions have been proposed, particularly: * (2015) Observing Resources in the Constrained Application Protocol * (2016) Block-Wise Transfers in the Constrained Application Protocol (CoAP) * (2018) CoAP (Constrained Application Protocol) over TCP, TLS, andMessage formats
CoAP makes use of two message types, requests and responses, using a simple, binary header format. CoAP is by default bound to UDP and optionally to DTLS, providing a high level of communications security. When bound to UDP, the entire message ''must'' fit within a single datagram. When used with 6LoWPAN as defined in RFC 4944, messages ''should'' fit into a singleCoAP fixed-size header
The first 4 bytes are mandatory in all CoAP datagrams, they constitute the fixed-size header. These fields can be extracted from these 4 bytes in C via these macros:Version (ver) (2 bits)
:Indicates the CoAP version number.Type (2 bits)
:This describes the datagram's message type for the two message type context of Request and Response. :* Request :** 0 : Confirmable : This message expects a corresponding acknowledgement message. :** 1 : Non-confirmable : This message does not expect a confirmation message. :* Response :** 2 : Acknowledgement : This message is a response that acknowledge a confirmable message :** 3 : Reset : This message indicates that it had received a message but could not process it.Token length (4 bits)
:Indicates the length of the variable-length Token field, which may be 0–8 bytes in length.Request/response code (8 bits)
The three most significant bits form a number known as the "class", which is analogous to the class of HTTP status codes. The five least significant bits form a code that communicates further detail about the request or response. The entire code is typically communicated in the formclass.code
.
You can find the latest CoAP request/response codes aMessage ID (16 bits)
:Used to detect message duplication and to match messages of type acknowledgement/reset to messages of type confirmable/non-confirmable.Token
Every request carries a token (but it may be zero length) whose value was generated by the client. The server must echo every token value without any modification back to the client in the corresponding response. It is intended for use as a client-local identifier to match requests and responses, especially for concurrent requests. Matching requests and responses is not done with the message ID because a response may be sent in a different message than the acknowledgement (which uses the message ID for matching). For example, this could be done to prevent retransmissions if obtaining the result takes some time. Such a detached response is called "separate response". In contrast, transmitting the response directly in the acknowledgement is called "piggybacked response" which is expected to be preferred for efficiency reasons.Option
Option delta: * 0 to 12: For delta between 0 and 12: Represents the exact delta value between the last option ID and the desired option ID, with no option delta extended value * 13: For delta from 13 to 268: Option delta extended is an 8-bit value that represents the option delta value minus 13 * 14: For delta from 269 to 65,804: Option delta extended is a 16-bit value that represents the option delta value minus 269 * 15: Reserved for payload marker, where the option delta and option length are set together as 0xFF. Option length: * 0 to 12: For option length between 0 and 12: Represents the exact length value, with no option length extended value * 13: For option length from 13 to 268: Option length extended is an 8-bit value that represents the option length value minus 13 * 14: For option length from 269 to 65,804: Option length extended is a 16-bit value that represents the option length value minus 269 * 15: Reserved for future use. It is an error for the option length field to be set to 0xFF. Option value: * Size of option value field is defined by option length value in bytes. * Semantic and format this field depends on the respective option.Active protocol implementations
Proxy implementations
There exist Proxy server, proxy implementations which provide forward or reverse proxy functionality for the CoAP protocol and also implementations which translate between protocols like HTTP and CoAP. The following projects provide proxy functionality:Projects using CoAP
Inactive protocol implementations
CoAP group communication
In many CoAP application domains it is essential to have the ability to address several CoAP resources as a group, instead of addressing each resource individually (e.g. to turn on all the CoAP-enabled lights in a room with a single CoAP request triggered by toggling the light switch). To address this need, the IETF has developed an optional extension for CoAP in the form of an experimental RFC: Group Communication for CoAP - RFC 7390 This extension relies on IP multicast to deliver the CoAP request to all group members. The use of multicast has certain benefits such as reducing the number of packets needed to deliver the request to the members. However, multicast also has its limitations such as poor reliability and being cache-unfriendly. An alternative method for CoAP group communication that uses unicasts instead of multicasts relies on having an intermediary where the groups are created. Clients send their group requests to the intermediary, which in turn sends individual unicast requests to the group members, collects the replies from them, and sends back an aggregated reply to the client.Security
CoAP defines four security modes: * NoSec, where DTLS is disabled * PreSharedKey, where DTLS is enabled, there is a list of pre-shared keys, and each key includes a list of which nodes it can be used to communicate with. Devices must support the AES cipher suite. * RawPublicKey, where DTLS is enabled and the device uses an asymmetric key pair without a certificate, which is validated out of band. Devices must support the AES cipher suite and Elliptic Curve algorithms for key exchange. * Certificate, where DTLS is enabled and the device uses X.509 certificates for validation. Research has been conducted on optimizing DTLS by implementing security associates as CoAP resources rather than using DTLS as a security wrapper for CoAP traffic. This research has indicated that improvements of up to 6.5 times none optimized implementations. In addition to DTLS, RFC8613 defines the Object Security for Constrained RESTful Environments ( OSCORE) protocol which provides security for CoAP at the application layer.Security issues
Although the protocol standard includes provisions for mitigating the threat ofSee also
*References
External links
{{commons category, SSL and TLS