37#ifndef PROTOCORE_COAP_H
38#define PROTOCORE_COAP_H
47enum class CoapType : uint8_t
56enum class CoapMethod : uint8_t
69 static constexpr uint8_t COAP_ALLOW_GET = 1u << (unsigned)CoapMethod::COAP_GET;
70 static constexpr uint8_t COAP_ALLOW_POST = 1u << (unsigned)CoapMethod::COAP_POST;
71 static constexpr uint8_t COAP_ALLOW_PUT = 1u << (unsigned)CoapMethod::COAP_PUT;
72 static constexpr uint8_t COAP_ALLOW_DELETE = 1u << (unsigned)CoapMethod::COAP_DELETE;
76#define COAP_CODE(c, dd) ((uint8_t)(((c) << 5) | ((dd) & 0x1F)))
79enum class CoapResponseCode : uint8_t
81 COAP_RSP_CREATED = COAP_CODE(2, 1),
82 COAP_RSP_DELETED = COAP_CODE(2, 2),
83 COAP_RSP_VALID = COAP_CODE(2, 3),
84 COAP_RSP_CHANGED = COAP_CODE(2, 4),
85 COAP_RSP_CONTENT = COAP_CODE(2, 5),
86 COAP_RSP_CONTINUE = COAP_CODE(2, 31),
87 COAP_RSP_BAD_REQUEST = COAP_CODE(4, 0),
88 COAP_RSP_BAD_OPTION = COAP_CODE(4, 2),
89 COAP_RSP_NOT_FOUND = COAP_CODE(4, 4),
90 COAP_RSP_METHOD_NOT_ALLOWED = COAP_CODE(4, 5),
91 COAP_RSP_NOT_ACCEPTABLE = COAP_CODE(4, 6),
92 COAP_RSP_REQUEST_INCOMPLETE = COAP_CODE(4, 8),
93 COAP_RSP_REQUEST_TOO_LARGE = COAP_CODE(4, 13),
94 COAP_RSP_INTERNAL_ERROR = COAP_CODE(5, 0),
95 COAP_RSP_NOT_IMPLEMENTED = COAP_CODE(5, 1),
99enum class CoapContentFormat : uint16_t
107 COAP_CF_NONE = 0xFFFF,
121 const uint8_t *payload;
123 CoapContentFormat content_format;
137 CoapContentFormat content_format;
144typedef void (*CoapHandler)(
const CoapRequest *req, CoapResponse *resp);
151void pc_coap_server_reset();
162bool pc_coap_server_add_resource(
const char *path, uint8_t methods, CoapHandler handler);
182size_t pc_coap_server_process(
const uint8_t *req,
size_t req_len, uint8_t *resp,
size_t pc_resp_cap);
189size_t pc_coap_server_process_ex(
const uint8_t *req,
size_t req_len, uint8_t *resp,
size_t pc_resp_cap,
190 int32_t observe_seq);
192#if PC_COAP_DEDUP_ENTRIES > 0
199bool pc_coap_dedup_lookup(
const char *src_ip, uint16_t src_port, uint16_t mid,
const uint8_t **out,
size_t *out_len);
205void pc_coap_dedup_store(
const char *src_ip, uint16_t src_port, uint16_t mid,
const uint8_t *resp,
size_t len);
218void pc_coap_server_begin(uint16_t port = 5683);
220#if PC_ENABLE_COAP_OBSERVE
231void pc_coap_notify(
const char *path);
User-facing configuration for ProtoCore.