ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
coap.h File Reference

The CoAP server (RFC 7252): the message codec, a fixed resource table, and the UDP binding. More...

#include "protocore_config.h"

Go to the source code of this file.

Detailed Description

The CoAP server (RFC 7252): the message codec, a fixed resource table, and the UDP binding.

RFC 7252 sec 3 gives the message: a 4-byte header carrying Version (Ver), Type (T), Token Length (TKL), Code and Message ID, then the Token of TKL bytes, then zero or more Options in TLV form, then the Payload behind the one-byte Payload Marker 0xFF.

A request is answered piggybacked (RFC 7252 sec 5.2.1): a Confirmable request takes an Acknowledgement carrying the response, a Non-confirmable request takes a Non-confirmable response (sec 5.2.3). Separate responses (sec 5.2.2) are not produced - a request is answered before its handler returns - and the server never sends a Confirmable message, so nothing is retransmitted.

Message deduplication (RFC 7252 sec 4.5) is kept: a Confirmable message repeated within PROTOCORE_COAP_DEDUP_LIFETIME_MS is recognized by its Message ID and source endpoint and re-answered from a cache, so the request is processed only once.

Resource discovery is served at "/.well-known/core" in the CoRE Link Format (RFC 6690 sec 4, sec 2). The codec reads the Uri-Path (11), Content-Format (12) and Uri-Query (15) options (RFC 7252 sec 5.10); an unrecognized option of class critical answers 4.02 Bad Option and an elective one is ignored (sec 5.4.1). Block-wise transfer with the Block2 (23) and Block1 (27) options (RFC 7959 sec 2.1) is compiled in by PROTOCORE_ENABLE_COAP_BLOCK; resource observation with the Observe (6) option (RFC 7641 sec 2) by PROTOCORE_ENABLE_COAP_OBSERVE.

The resource table is a fixed array of PROTOCORE_COAP_MAX_RESOURCES rows in storage. A path is referenced by pointer and must outlive the server.

The module exports one symbol, Coap. Everything in coap.c has internal linkage.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file coap.h.