20#ifndef INET6_ADDRSTRLEN
21#define INET6_ADDRSTRLEN 46
24#if COAP_CLIENT_SUPPORT == 0
25#error For Proxy support, COAP_CLIENT_SUPPORT must be set
27#if COAP_SERVER_SUPPORT == 0
28#error For Proxy support, COAP_SERVER_SUPPORT must be set
32#define strcasecmp _stricmp
33#define strncasecmp _strnicmp
56 scratch_d[0] =
'\000';
58 size = strlen(scratch_d);
59 snprintf(&scratch_d[size],
sizeof(scratch_d)-size,
62 scratch_u[0] =
'\000';
64 for (i = 0; i < upstream_token->
length; i++) {
65 size = strlen(scratch_u);
66 snprintf(&scratch_u[size],
sizeof(scratch_u)-size,
67 "%02x", upstream_token->
s[i]);
71 coap_log_debug(
" proxy %-4s %s {%s}-{%s} \"%s\"%s\n", type, addr, scratch_u, scratch_d,
80 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"del");
85 if (proxy_req->proxy_cache) {
92 url ? (
char *)url->
s :
"???",
93 proxy_req->proxy_cache->ref);
96 assert(proxy_req->proxy_cache->ref);
97 proxy_req->proxy_cache->ref--;
98 if (proxy_req->proxy_cache->ref == 0) {
99 PROXY_CACHE_DELETE(proxy_entry->rsp_cache, proxy_req->proxy_cache);
103 proxy_req->proxy_cache =
NULL;
105 if (proxy_req->doing_observe) {
106 assert(proxy_req->incoming->ref_proxy_subs);
107 proxy_req->incoming->ref_proxy_subs--;
108 proxy_req->doing_observe = 0;
112 proxy_req->incoming =
NULL;
114 LL_DELETE(proxy_entry->proxy_req, proxy_req);
120 coap_proxy_req_t *proxy_req, *treq;
122 LL_FOREACH_SAFE(proxy_entry->proxy_req, proxy_req, treq) {
140 coap_log_debug(
"Cannot add token to incoming proxy response PDU\n");
144 coap_log_info(
"Failed to send PDU with %u.%02u proxy issue\n",
149 coap_proxy_del_req(proxy_entry, proxy_req);
158 for (i = 0; i < context->proxy_list_count; i++) {
161 (
void *)&context->proxy_list[i]);
162 coap_proxy_cleanup_entry(&context->proxy_list[i], 0);
169 if (proxy_entry && proxy_entry->ongoing) {
173 LL_FOREACH(proxy_entry->ongoing->lg_crcv, lg_crcv) {
174 if (lg_crcv->observe_set) {
193 for (i = 0; i < context->proxy_list_count; i++) {
196 if (coap_proxy_check_observe(proxy_entry))
199 if (proxy_entry->ongoing) {
200 if (proxy_entry->req_start_ticks) {
204 if (timeout_time <= now) {
209 proxy_entry->mid,
NULL, &sent);
217 if (*tim_rem > timeout_time - now) {
218 *tim_rem = timeout_time - now;
222 }
else if (proxy_entry->idle_timeout_ticks) {
223 if (proxy_entry->last_used + proxy_entry->idle_timeout_ticks <= now) {
225 if (coap_proxy_remove_association(proxy_entry->ongoing, 0)) {
229 if (*tim_rem > proxy_entry->last_used + proxy_entry->idle_timeout_ticks - now) {
230 *tim_rem = proxy_entry->last_used + proxy_entry->idle_timeout_ticks - now;
241coap_get_uri_proxy_scheme_info(
const coap_pdu_t *request,
249 strncasecmp(opt_val,
"coaps+tcp", 9) == 0) {
252 }
else if (opt_len == 8 &&
253 strncasecmp(opt_val,
"coap+tcp", 8) == 0) {
256 }
else if (opt_len == 5 &&
257 strncasecmp(opt_val,
"coaps", 5) == 0) {
260 }
else if (opt_len == 4 &&
261 strncasecmp(opt_val,
"coap", 4) == 0) {
264 }
else if (opt_len == 7 &&
265 strncasecmp(opt_val,
"coap+ws", 7) == 0) {
268 }
else if (opt_len == 8 &&
269 strncasecmp(opt_val,
"coaps+ws", 8) == 0) {
274 opt_len, opt_len, opt_val);
316 coap_log_warn(
"coap+tcp URI scheme not supported for proxy\n");
322 coap_log_warn(
"coaps+tcp URI scheme not supported for proxy\n");
328 coap_log_warn(
"coap+ws URI scheme not supported for proxy\n");
334 coap_log_warn(
"coaps+ws URI scheme not supported for proxy\n");
350 switch ((
int)proxy_type) {
372 coap_log_warn(
"Proxy old proxy_type 0x%u unknow\n", proxy_type);
386 size_t proxy_list_count = context->proxy_list_count;
391 for (i = 0; i < proxy_list_count; i++) {
393 proxy_list[i].uri.port == uri.
port &&
394 proxy_list[i].uri.scheme == uri.
scheme) {
395 if (!proxy_list[i].track_client_session && context->proxy_response_cb) {
397 return &proxy_list[i];
399 if (proxy_list[i].incoming == incoming) {
401 return &proxy_list[i];
411 (proxy_list_count+1)*
sizeof(proxy_list[0]));
413 if (new_proxy_list ==
NULL) {
416 context->proxy_list = proxy_list = new_proxy_list;
417 memset(&proxy_list[proxy_list_count], 0,
sizeof(proxy_list[proxy_list_count]));
420 proxy_list[proxy_list_count].uri = uri;
423 if (!proxy_list[proxy_list_count].uri_host_keep) {
426 memcpy(proxy_list[proxy_list_count].uri_host_keep, uri.
host.
s, uri.
host.
length);
427 proxy_list[proxy_list_count].uri.host.s = proxy_list[proxy_list_count].uri_host_keep;
429 proxy_list[proxy_list_count].uri.path.s =
NULL;
430 proxy_list[proxy_list_count].uri.path.length = 0;
431 proxy_list[proxy_list_count].uri.query.s =
NULL;
432 proxy_list[proxy_list_count].uri.query.length = 0;
434 proxy_list[proxy_list_count].ongoing = ongoing;
435 proxy_list[proxy_list_count].idle_timeout_ticks = server_list->
idle_timeout_secs *
438 coap_ticks(&proxy_list[proxy_list_count].last_used);
440 incoming->proxy_entry = &proxy_list[proxy_list_count];
442 proxy_list[proxy_list_count].incoming = incoming;
443 incoming->proxy_entry = &proxy_list[proxy_list_count];
446 context->proxy_list_count++;
447 return &proxy_list[proxy_list_count];
458 size_t proxy_list_count = session->
context->proxy_list_count;
464 *proxy_entry_created = 0;
470 if (session->proxy_entry) {
471 for (i = 0; i < proxy_list_count; i++) {
472 if (&proxy_list[i] == session->proxy_entry) {
473 if (session->proxy_entry->ongoing) {
474 memset(server_use, 0,
sizeof(*server_use));
475 return session->proxy_entry;
487 memcpy(server_use, &server_list->
entry[server_list->
next_entry],
sizeof(*server_use));
489 memset(server_use, 0,
sizeof(*server_use));
492 proxy_type = coap_proxy_map_type(server_list->
type);
501 if (!coap_get_uri_proxy_scheme_info(request, proxy_scheme, &server_use->
uri)) {
516 &server_use->
uri) < 0) {
524 if (!(proxy_scheme || proxy_uri)) {
542 proxy_entry = coap_proxy_get_add_list_entry(session,
NULL, server_use->
uri, server_list, 0);
544 if (proxy_entry ==
NULL) {
549 *proxy_entry_created = 1;
558 size_t proxy_list_count = session->
context->proxy_list_count;
560 for (i = 0; i < proxy_list_count; i++) {
562 coap_proxy_req_t *proxy_req;
566 LL_FOREACH(proxy_entry->proxy_req, proxy_req) {
567 if (proxy_req->incoming == session) {
568 coap_proxy_del_req(proxy_entry, proxy_req);
572 if (proxy_entry->incoming == session) {
576 proxy_entry->ongoing =
NULL;
582 if (proxy_entry->ongoing == session) {
585 coap_proxy_cleanup_entry(proxy_entry, failure_code);
586 ongoing = proxy_entry->ongoing;
590 session->
context->proxy_list_count - 1);
591 if (proxy_list_count-i > 1) {
592 memmove(&proxy_list[i],
594 (proxy_list_count-i-1) *
sizeof(proxy_list[0]));
596 session->
context->proxy_list_count--;
615 static char client_sni[256];
617 int proxy_entry_created;
619 proxy_entry = coap_proxy_get_session(session, request, response, server_list,
620 &server_use, &proxy_entry_created);
626 if (!proxy_entry->ongoing) {
640 if (info_list ==
NULL) {
642 coap_proxy_remove_association(session, 0);
645 proto = info_list->
proto;
646 memcpy(&dst, &info_list->
addr,
sizeof(dst));
654 coap_proxy_remove_association(session, 0);
661 coap_proxy_remove_association(session, 0);
662 coap_log_debug(
"* %s: mcast proxy forwarding only supported for 'coap'\n",
668#if COAP_AF_UNIX_SUPPORT
677 "/tmp/coap-pr-cl-%" PRIu64, (uint64_t)now);
680 fprintf(stderr,
"coap_address_set_unix_domain: %s: failed\n",
686 local_addr = &bind_addr;
690 snprintf(client_sni,
sizeof(client_sni),
"%*.*s", (
int)server_use.
uri.
host.
length,
697#if COAP_OSCORE_SUPPORT
699 proxy_entry->ongoing =
705 proxy_entry->ongoing =
708#if COAP_OSCORE_SUPPORT
715#if COAP_OSCORE_SUPPORT
719 proxy_entry->ongoing =
726 proxy_entry->ongoing =
732 coap_log_warn(
"Proxy: (D)TLS not configured for secure session\n");
739 proxy_entry->ongoing =
745 proxy_entry->ongoing =
751 proxy_entry->ongoing =
755#if COAP_OSCORE_SUPPORT
766 if (proxy_entry->ongoing ==
NULL) {
768 coap_proxy_remove_association(session, 0);
771 if (proxy_entry_created) {
774 (
int)proxy_entry->uri.host.length, proxy_entry->uri.host.s,
775 proxy_entry->uri.port,
777 session->
context->proxy_list_count);
779 }
else if (proxy_entry->ongoing->session_failed) {
795static coap_proxy_req_t *
798 coap_proxy_req_t *proxy_req;
800 LL_FOREACH(proxy_entry->proxy_req, proxy_req) {
801 if (proxy_req->incoming == session && proxy_req->proxy_cache == proxy_cache) {
816 coap_proxy_req_t *proxy_req,
int replace_mid,
817 int remove_observe) {
835 if (remove_observe) {
854 resp_pdu->
type = proxy_req->pdu->type;
860 resp_pdu->
mid = sent->
mid;
862 proxy_req->mid = resp_pdu->
mid;
870 uint16_t media_type = 0;
878 assert(size == total);
882 coap_log_debug(
"coap_proxy_call_response_handler: copy data error\n");
902 if (!coap_add_data_large_response_lkd(proxy_req->resource, session, sent,
905 media_type, maxage, etag, body->
length,
907 coap_proxy_free_response_data,
909 coap_log_debug(
"coap_proxy_call_response_handler: add data error\n");
914 session->
context->proxy_response_cb(session,
917 proxy_req->cache_key),
925 if (fwd_pdu != resp_pdu) {
948 ret = coap_proxy_forward_request_lkd(session,
983 coap_proxy_req_t *proxy_req =
NULL;
991 coap_proxy_cache_t *proxy_cache =
NULL;
1000 proxy_entry = coap_proxy_get_ongoing_session(session, request, response,
1006 coap_proxy_log_entry(session, request,
NULL,
"req");
1009 if (obs_opt && session->
context->proxy_response_cb) {
1014 coap_proxy_ignore_options,
1015 sizeof(coap_proxy_ignore_options)/
sizeof(coap_proxy_ignore_options[0]));
1020 PROXY_CACHE_FIND(proxy_entry->rsp_cache, cache_key_l, proxy_cache);
1025 proxy_req = coap_proxy_get_req(proxy_entry, proxy_cache, session);
1034 if (proxy_req->doing_observe) {
1035 assert(proxy_req->incoming->ref_proxy_subs);
1036 proxy_req->incoming->ref_proxy_subs--;
1037 proxy_req->doing_observe = 0;
1039 if (proxy_entry->proxy_req && !proxy_entry->proxy_req->next &&
1040 proxy_req->token_used) {
1043 coap_log_debug(
"coap_proxy_forward_request: Using coap_cancel_observe() to do Proxy OBSERVE cancellation\n");
1045 memcpy(&tmp.
s, &proxy_req->token_used->s,
sizeof(tmp.
s));
1046 tmp.
length = proxy_req->token_used->length;
1052 goto return_cached_info;
1058 coap_proxy_del_req(proxy_entry, proxy_req);
1062 goto return_cached_info;
1068 coap_proxy_del_req(proxy_entry, proxy_req);
1072 goto return_cached_info;
1080 if (proxy_req ==
NULL) {
1083 memset(proxy_req, 0,
sizeof(coap_proxy_req_t));
1084 LL_PREPEND(proxy_entry->proxy_req, proxy_req);
1087 proxy_req->resource = resource;
1088 proxy_req->incoming = session;
1089 proxy_req->cache_key = cache_key;
1090 proxy_req->proxy_cache = proxy_cache;
1092 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"add");
1103 if (proxy_req->token_used ==
NULL) {
1106 goto return_cached_info;
1113 if (proxy_req->token_used ==
NULL) {
1120 proxy_type = coap_proxy_map_type(server_list->
type);
1137 if (
coap_is_mcast(&proxy_entry->ongoing->addr_info.remote)) {
1148 switch (opt_iter.
number) {
1202 assert(size == total);
1212 memcpy(body_data->
s, data, size);
1213 if (!coap_add_data_large_request_lkd(proxy_entry->ongoing, pdu, total, data,
1214 coap_proxy_release_body_data, body_data)) {
1220 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"fwd");
1221 proxy_entry->mid =
coap_send_lkd(proxy_entry->ongoing, pdu);
1228 proxy_entry->req_start_ticks = now;
1245 if (obs_opt && !proxy_req->doing_observe) {
1252 proxy_req->doing_observe = 1;
1253 proxy_req->incoming->ref_proxy_subs++;
1259 coap_proxy_log_entry(session, request, &proxy_cache->rsp_pdu->actual_token,
"rspc");
1260 if (now < proxy_cache->expire) {
1262 if (new_maxage == 0)
1270 coap_proxy_call_response_handler(session, request, proxy_cache->rsp_pdu,
1271 &r_token, proxy_req, 1, obs_opt ? 0 : 1);
1273 coap_proxy_del_req(proxy_entry, proxy_req);
1282 size_t proxy_list_count = ongoing->
context->proxy_list_count;
1286 coap_proxy_req_t *proxy_req;
1288 for (i = 0; i < proxy_list_count; i++) {
1289 proxy_entry = &proxy_list[i];
1290 if (proxy_entry->ongoing == ongoing) {
1291 LL_FOREACH(proxy_entry->proxy_req, proxy_req) {
1295 *u_proxy_entry = proxy_entry;
1305 scratch[0] =
'\000';
1306 for (i = 0; i < rcv_token.
length; i++) {
1307 size = strlen(scratch);
1308 snprintf(&scratch[size],
sizeof(scratch)-size,
1309 "%02x", rcv_token.
s[i]);
1312 for (i = 0; i < proxy_list_count; i++) {
1313 proxy_entry = &proxy_list[i];
1314 LL_FOREACH(proxy_entry->proxy_req, proxy_req) {
1315 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"miss");
1329 ret = coap_proxy_forward_response_lkd(session,
1343 const uint8_t *data;
1358 coap_proxy_req_t *proxy_req =
NULL;
1360 proxy_req = coap_proxy_map_outgoing_request(session, received, &proxy_entry);
1361 if (!proxy_req || proxy_req->incoming->server_list) {
1362 coap_log_warn(
"Unknown proxy ongoing session response received - ignored\n");
1366 proxy_entry->req_start_ticks = 0;
1367 req_pdu = proxy_req->pdu;
1369 resource = proxy_req->resource;
1370 incoming = proxy_req->incoming;
1372 coap_log_debug(
"** process upstream incoming %d.%02d response:\n",
1377 assert(size == total);
1383 memcpy(body_data->
s, data, size);
1384 data = body_data->
s;
1400 coap_log_debug(
"cannot add token to ongoing proxy response PDU\n");
1409 switch (opt_iter.
number) {
1440 coap_add_data_large_response_lkd(resource, incoming, req_pdu, pdu,
1442 media_type, maxage, etag, size, data,
1443 coap_proxy_release_body_data,
1450 *cache_key = proxy_req->cache_key;
1457 if (option ==
NULL) {
1458 if (proxy_entry->proxy_req) {
1460 proxy_req->cache_key =
NULL;
1461 coap_proxy_del_req(proxy_entry, proxy_req);
1463 }
else if (!proxy_req->doing_observe) {
1468 proxy_req->doing_observe = 1;
1469 proxy_req->incoming->ref_proxy_subs++;
1479 void *body_data, coap_proxy_req_t *proxy_req,
1489 switch ((
int)rcvd->
code) {
1506 if (can_cache && obs_opt) {
1507 coap_proxy_cache_t *proxy_cache;
1513 if (proxy_req->proxy_cache) {
1515 proxy_cache = proxy_req->proxy_cache;
1518 if (proxy_cache ==
NULL) {
1521 memset(proxy_cache, 0,
sizeof(coap_proxy_cache_t));
1524 coap_proxy_ignore_options,
1525 sizeof(coap_proxy_ignore_options)/
sizeof(coap_proxy_ignore_options[0]));
1530 memcpy(&proxy_cache->cache_req, cache_key_l,
1531 sizeof(proxy_cache->cache_req));
1535 proxy_req->proxy_cache = proxy_cache;
1537 PROXY_CACHE_ADD(proxy_entry->rsp_cache, proxy_cache);
1542 const uint8_t *data;
1550 if (proxy_cache->rsp_pdu) {
1556 memcpy(copy->
s, data, data_len);
1557 proxy_cache->rsp_pdu->data_free = copy;
1558 proxy_cache->rsp_pdu->body_data = copy->
s;
1559 proxy_cache->rsp_pdu->body_length = copy->
length;
1560 proxy_cache->rsp_pdu->body_total = copy->
length;
1562 proxy_cache->rsp_pdu->body_data =
NULL;
1563 proxy_cache->rsp_pdu->body_length = 0;
1564 proxy_cache->rsp_pdu->body_total = 0;
1577 proxy_cache->etag = 0;
1591 LL_FOREACH(proxy_entry->proxy_req, proxy_req) {
1592 if (proxy_req->proxy_cache == proxy_cache) {
1593 if (!proxy_req->doing_observe) {
1600 proxy_req->doing_observe = 1;
1601 proxy_req->incoming->ref_proxy_subs++;
1604 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"rsp");
1606 if (coap_proxy_call_response_handler(proxy_req->incoming, proxy_req->pdu,
1617 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"rspn");
1619 ret = coap_proxy_call_response_handler(proxy_req->incoming, proxy_req->pdu,
1620 rcvd, &token, proxy_req, 0, 0);
1622 coap_proxy_del_req(proxy_entry, proxy_req);
1643 resource = session->
context->unknown_resource ?
1644 session->
context->unknown_resource :
1645 session->
context->proxy_uri_resource;
1647 coap_log_err(
"coap_proxy_local_write: Unknown or Proxy resource not defined\n");
1655 coap_log_err(
"coap_proxy_local_write: Could not create response PDU\n");
1671 if (!coap_proxy_forward_request_lkd(session, pdu, response, resource,
1672 NULL, session->server_list)) {
1673 coap_log_debug(
"coap_proxy_local_write: Failed to forward PDU\n");
1688 session = coap_new_client_session_proxy_lkd(ctx, server_list);
1702#if COAP_IPV6_SUPPORT
1703 remote.
s = (
const uint8_t *)
"::1";
1704#elif COAP_IPV4_SUPPORT
1705 remote.
s = (
const uint8_t *)
"127.0.0.1";
1707 coap_log_warn(
"coap_new_client_session_proxy: No IPv4 or IPv6 support\n");
1710 remote.
length = strlen((
const char *)remote.
s);
1717 coap_log_warn(
"coap_new_client_session_proxy: Unable to resolve IP address\n");
1725 session->server_list = server_list;
1738 ret = coap_proxy_fwd_add_client_session_lkd(session, use_ip, use_port, server_list);
1744coap_proxy_fwd_add_client_session_lkd(
coap_session_t *session,
const char *use_ip,
1747#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI)
1761 memset(&uri, 0,
sizeof(uri));
1762 uri.
port = use_port;
1763 switch (session->
proto) {
1799 if (memcmp(use_ip,
"::ffff:", 7) == 0) {
1801 uri.
host.
s = (
const uint8_t *)&use_ip[7];
1804 uri.
host.
s = (
const uint8_t *)use_ip;
1810 proxy_entry = coap_proxy_get_add_list_entry(
NULL, session, uri, server_list, 1);
1814 (
int)proxy_entry->uri.host.length, proxy_entry->uri.host.s,
1815 proxy_entry->uri.port,
1816 (
void *)proxy_entry,
1817 session->
context->proxy_list_count);
1818 proxy_entry->idle_timeout_ticks = 0;
1819 proxy_entry->req_start_ticks = 0;
1820 proxy_entry->track_client_session = 0;
1829 coap_mid_t mid, coap_proxy_subs_delete_t type) {
1834 for (i = 0; i < context->proxy_list_count; i++) {
1836 coap_proxy_req_t *proxy_req, *treq;
1838 LL_FOREACH_SAFE(proxy_entry->proxy_req, proxy_req, treq) {
1839 if (proxy_req->incoming == session) {
1845 case COAP_PROXY_SUBS_ALL:
1848 case COAP_PROXY_SUBS_TOKEN:
1852 case COAP_PROXY_SUBS_MID:
1853 if (proxy_req->mid == mid)
1860 if (match && proxy_entry->proxy_req && ! proxy_entry->proxy_req->next &&
1861 proxy_req->token_used) {
1864 coap_log_debug(
"coap_delete_proxy_subscriber: Using coap_cancel_observe() to do Proxy OBSERVE cancellation\n");
1866 memcpy(&tmp.
s, &proxy_req->token_used->s,
sizeof(tmp.
s));
1867 tmp.
length = proxy_req->token_used->length;
1870 coap_proxy_del_req(proxy_entry, proxy_req);
int coap_address_set_unix_domain(coap_address_t *addr, const uint8_t *host, size_t host_len)
Copy the parsed unix domain host into coap_address_t structure translating %2F into / on the way.
void coap_free_address_info(coap_addr_info_t *info)
Free off the one or more linked sets of coap_addr_info_t returned from coap_resolve_address_info().
int coap_is_af_unix(const coap_address_t *a)
Checks if given address a denotes a AF_UNIX address.
int coap_is_mcast(const coap_address_t *a)
Checks if given address a denotes a multicast address.
@ COAP_RESOLVE_TYPE_REMOTE
remote side of session
#define COAP_UNIX_PATH_MAX
struct coap_lg_crcv_t coap_lg_crcv_t
struct coap_cache_key_t coap_cache_key_t
struct coap_proxy_entry_t coap_proxy_entry_t
Proxy information.
struct coap_resource_t coap_resource_t
Library specific build wrapper for coap_internal.h.
void * coap_realloc_type(coap_memory_tag_t type, void *p, size_t size)
Reallocates a chunk p of bytes created by coap_malloc_type() or coap_realloc_type() and returns a poi...
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
@ COAP_OPTION_PROXY_SCHEME
@ COAP_OPTION_CONTENT_FORMAT
coap_uri_scheme_t
The scheme specifiers.
@ COAP_URI_SCHEME_COAPS_WS
@ COAP_URI_SCHEME_COAPS_TCP
@ COAP_URI_SCHEME_COAP_TCP
@ COAP_URI_SCHEME_COAP_WS
coap_mid_t coap_send_rst_lkd(coap_session_t *session, const coap_pdu_t *request)
Sends an RST message with code 0 for the specified request to dst.
coap_mid_t coap_send_error_lkd(coap_session_t *session, const coap_pdu_t *request, coap_pdu_code_t code, coap_opt_filter_t *opts)
Sends an error response with code code for request request to dst.
coap_mid_t coap_send_lkd(coap_session_t *session, coap_pdu_t *pdu)
Sends a CoAP message to given peer.
coap_mid_t coap_send_ack_lkd(coap_session_t *session, const coap_pdu_t *request)
Sends an ACK message with code 0 for the specified request to dst.
void coap_delete_cache_key(coap_cache_key_t *cache_key)
Delete the cache-key.
coap_cache_key_t * coap_cache_derive_key_w_ignore(const coap_session_t *session, const coap_pdu_t *pdu, coap_cache_session_based_t session_based, const uint16_t *ignore_options, size_t ignore_count)
Calculates a cache-key for the given CoAP PDU.
@ COAP_CACHE_NOT_SESSION_BASED
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
#define COAP_TICKS_PER_SECOND
Use ms resolution on POSIX systems.
#define COAP_MAX_DELAY_TICKS
uint16_t coap_new_message_id_lkd(coap_session_t *session)
Returns a new message id and updates session->tx_mid accordingly.
int coap_delete_node_lkd(coap_queue_t *node)
Destroys specified node.
int coap_option_check_critical(coap_session_t *session, coap_pdu_t *pdu, coap_opt_filter_t *unknown, coap_crit_type_t is_proxy)
Verifies that pdu contains no unknown critical options, duplicate options or the options defined as R...
coap_addr_info_t * coap_resolve_address_info_lkd(const coap_str_const_t *address, uint16_t port, uint16_t secure_port, uint16_t ws_port, uint16_t ws_secure_port, int ai_hints_flags, int scheme_hint_bits, coap_resolve_type_t type)
Resolve the specified address into a set of coap_address_t that can be used to bind() (local) or conn...
int coap_remove_from_queue(coap_queue_t **queue, coap_session_t *session, coap_mid_t mid, coap_bin_const_t *token, coap_queue_t **node)
This function removes the element with given id from the list given list.
void coap_ticks(coap_tick_t *t)
Returns the current value of an internal tick counter.
@ COAP_RESPONSE_FAIL
Response not liked - send CoAP RST packet.
@ COAP_RESPONSE_OK
Response is fine.
unsigned int coap_encode_var_safe(uint8_t *buf, size_t length, unsigned int val)
Encodes multiple-length byte sequences.
unsigned int coap_decode_var_bytes(const uint8_t *buf, size_t len)
Decodes multiple-length byte sequences.
uint64_t coap_decode_var_bytes8(const uint8_t *buf, size_t len)
Decodes multiple-length byte sequences.
#define coap_lock_callback_ret_release(r, func, failed)
Dummy for no thread-safe code.
#define coap_lock_unlock()
Dummy for no thread-safe code.
#define coap_lock_check_locked()
Dummy for no thread-safe code.
#define coap_lock_lock(failed)
Dummy for no thread-safe code.
#define coap_log_debug(...)
coap_log_t coap_get_log_level(void)
Get the current logging level.
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu)
Display the contents of the specified pdu.
size_t coap_print_addr(const coap_address_t *addr, unsigned char *buf, size_t len)
Print the address into the defined buffer.
const char * coap_session_str(const coap_session_t *session)
Get session description.
const char * coap_print_ip_addr(const coap_address_t *addr, char *buf, size_t len)
Print the IP address into the defined buffer.
#define coap_log_info(...)
#define coap_log_warn(...)
#define coap_log_err(...)
#define COAP_OBSERVE_CANCEL
The value COAP_OBSERVE_CANCEL in a GET/FETCH request option COAP_OPTION_OBSERVE indicates that the ob...
#define COAP_OBSERVE_ESTABLISH
The value COAP_OBSERVE_ESTABLISH in a GET/FETCH request option COAP_OPTION_OBSERVE indicates a new ob...
coap_opt_t * coap_option_next(coap_opt_iterator_t *oi)
Updates the iterator oi to point to the next option.
coap_optlist_t * coap_new_optlist(coap_option_num_t number, size_t length, const uint8_t *data)
Create a new optlist entry.
uint32_t coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option.
coap_opt_iterator_t * coap_option_iterator_init(const coap_pdu_t *pdu, coap_opt_iterator_t *oi, const coap_opt_filter_t *filter)
Initializes the given option iterator oi to point to the beginning of the pdu's option list.
void coap_delete_optlist(coap_optlist_t *queue)
Removes all entries from the optlist_chain, freeing off their memory usage.
#define COAP_OPT_ALL
Pre-defined filter that includes all options.
int coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t **options)
The current optlist of optlist_chain is first sorted (as per RFC7272 ordering requirements) and then ...
void coap_option_filter_clear(coap_opt_filter_t *filter)
Clears filter filter.
coap_opt_t * coap_check_option(const coap_pdu_t *pdu, coap_option_num_t number, coap_opt_iterator_t *oi)
Retrieves the first option of number number from pdu.
int coap_insert_optlist(coap_optlist_t **head, coap_optlist_t *node)
Adds optlist to the given optlist_chain.
const uint8_t * coap_opt_value(const coap_opt_t *opt)
Returns a pointer to the value of the given option.
int coap_option_filter_set(coap_opt_filter_t *filter, coap_option_num_t option)
Sets the corresponding entry for number in filter.
coap_session_t * coap_new_client_session_oscore3_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_oscore_conf_t *oscore_conf, void *app_data, coap_app_data_free_callback_t callback, coap_str_const_t *ws_host)
Creates a new client session to the designated server, protecting the data using OSCORE,...
coap_session_t * coap_new_client_session_oscore_psk3_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_cpsk_t *psk_data, coap_oscore_conf_t *oscore_conf, void *app_data, coap_app_data_free_callback_t callback, coap_str_const_t *ws_host)
Creates a new client session to the designated server, with PSK credentials protecting the data using...
coap_session_t * coap_new_client_session_oscore_pki3_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_pki_t *pki_data, coap_oscore_conf_t *oscore_conf, void *app_data, coap_app_data_free_callback_t callback, coap_str_const_t *ws_host)
Creates a new client session to the designated server, with PKI credentials protecting the data using...
coap_pdu_t * coap_pdu_reference_lkd(coap_pdu_t *pdu)
Increment reference counter on a pdu to stop it prematurely getting freed off when coap_delete_pdu() ...
void coap_delete_pdu_lkd(coap_pdu_t *pdu)
Dispose of an CoAP PDU and free off associated storage.
coap_pdu_t * coap_pdu_duplicate_lkd(const coap_pdu_t *old_pdu, coap_session_t *session, size_t token_length, const uint8_t *token, coap_opt_filter_t *drop_options, coap_bool_t expand_opt_abb)
Duplicate an existing PDU.
size_t coap_update_option(coap_pdu_t *pdu, coap_option_num_t number, size_t len, const uint8_t *data)
Updates existing first option of given number in the pdu with the new data.
size_t coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto)
Compose the protocol specific header for the specified PDU.
coap_pdu_t * coap_const_pdu_reference_lkd(const coap_pdu_t *pdu)
Increment reference counter on a const pdu to stop it prematurely getting freed off when coap_delete_...
COAP_STATIC_INLINE void coap_pdu_release_lkd(coap_pdu_t *pdu)
coap_pdu_code_t coap_pdu_get_code(const coap_pdu_t *pdu)
Gets the PDU code associated with pdu.
#define COAP_DEFAULT_PORT
int coap_mid_t
coap_mid_t is used to store the CoAP Message ID of a CoAP PDU.
#define COAP_RESPONSE_CODE(N)
#define COAP_RESPONSE_CLASS(C)
coap_proto_t
CoAP protocol types Note: coap_layers_coap[] needs updating if extended.
coap_pdu_code_t
Set of codes available for a PDU.
#define COAP_MEDIATYPE_TEXT_PLAIN
int coap_add_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds token of length len to pdu.
#define COAPS_DEFAULT_PORT
int coap_get_data(const coap_pdu_t *pdu, size_t *len, const uint8_t **data)
Retrieves the length and data pointer of specified PDU.
coap_pdu_t * coap_pdu_init(coap_pdu_type_t type, coap_pdu_code_t code, coap_mid_t mid, size_t size)
Creates a new CoAP PDU with at least enough storage space for the given size maximum message size.
int coap_get_data_large(const coap_pdu_t *pdu, size_t *len, const uint8_t **data, size_t *offset, size_t *total)
Retrieves the data from a PDU, with support for large bodies of data that spans multiple PDUs.
#define COAP_INVALID_MID
Indicates an invalid message id.
coap_bin_const_t coap_pdu_get_token(const coap_pdu_t *pdu)
Gets the token associated with pdu.
COAP_API coap_session_t * coap_new_client_session_proxy(coap_context_t *context, coap_proxy_server_list_t *server_list)
Creates a new client session to use the proxy logic going to the defined upstream server.
coap_proxy_t
coap_proxy_t Proxy definitions.
COAP_API int coap_proxy_forward_request(coap_session_t *session, const coap_pdu_t *request, coap_pdu_t *response, coap_resource_t *resource, coap_cache_key_t *cache_key, coap_proxy_server_list_t *server_list)
Forward incoming request upstream to the next proxy/server.
#define COAP_PROXY_NEW_MASK
Space used in coap_proxy_t for new types.
int coap_verify_proxy_scheme_supported(coap_uri_scheme_t scheme)
Verify that the CoAP Scheme is supported for an ongoing proxy connection.
COAP_API coap_proxy_entry_t * coap_proxy_fwd_add_client_session(coap_session_t *session, const char *use_ip, uint16_t use_port, coap_proxy_server_list_t *server_list)
Add a previously setup proxy-client session to use the proxy logic for forwarding subsequent dynamic ...
COAP_API coap_response_t coap_proxy_forward_response(coap_session_t *session, const coap_pdu_t *received, coap_cache_key_t **cache_key)
Forward the returning response back to the appropriate client.
@ COAP_PROXY_DIRECT_STRIP
Old - do not use - Act as a forward-dynamic proxy, strip out proxy options.
@ COAP_PROXY_BIT_STRIP
If COAP_PROXY_BIT_STRIP set, then remove any Proxy-Uri or Proxy-Scheme as the PDU is forwarded,...
@ COAP_PROXY_REVERSE_STRIP
Old - do not use - Act as a reverse proxy, strip out proxy options.
@ COAP_PROXY_FWD_STATIC
forward-static proxy.
@ COAP_PROXY_REV
reverse proxy.
@ COAP_PROXY_REVERSE
Old - do not use - Act as a reverse proxy.
@ COAP_PROXY_DIRECT
Old - do not use - Act as a forward-dynamic proxy.
@ COAP_PROXY_DYN_DEFINED
If COAP_PROXY_DYN_DEFINED set, then no new dynamic upstream servers will get automatically added.
@ COAP_PROXY_FORWARD_STRIP
Old - do not use - Act as a forward-static proxy, strip out proxy options.
@ COAP_PROXY_FWD_DYNAMIC
forward-dynamic proxy.
@ COAP_PROXY_FORWARD
Old - do not use - Act as a forward-static proxy.
@ COAP_PROXY_BIT_MCAST
If COAP_PROXY_BIT_MCAST set, then upstream servers can be multicast, else only unicast.
coap_session_t * coap_new_client_session_pki3_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_pki_t *setup_data, void *app_data, coap_app_data_free_callback_t callback, coap_str_const_t *ws_host)
Creates a new client session to the designated server, with PKI credentials along with app_data infor...
#define COAP_MAX_TRANSMIT_WAIT_TICKS(s)
coap_session_t * coap_new_client_session_psk3_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_cpsk_t *setup_data, void *app_data, coap_app_data_free_callback_t callback, coap_str_const_t *ws_host)
Creates a new client session to the designated server, with PSK credentials along with app_data infor...
int coap_session_reconnect(coap_session_t *session)
Close the current session (if not already closed) and reconnect to server (client session only).
size_t coap_session_max_pdu_size_lkd(const coap_session_t *session)
Get maximum acceptable PDU size.
void coap_session_release_lkd(coap_session_t *session)
Decrement reference counter on a session.
coap_session_t * coap_new_client_session3_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, void *app_data, coap_app_data_free_callback_t callback, coap_str_const_t *ws_host)
Creates a new client session to the designated server, with PSK credentials along with app_data infor...
int coap_session_set_type_client_lkd(coap_session_t *session, int report_changed)
Set the session type to client.
#define COAP_PROTO_NOT_RELIABLE(p)
void coap_session_new_token(coap_session_t *session, size_t *len, uint8_t *data)
Creates a new token for use.
const coap_address_t * coap_session_get_addr_remote(const coap_session_t *session)
Get the remote IP address and port from the session.
void coap_delete_bin_const(coap_bin_const_t *s)
Deletes the given const binary data and releases any memory allocated.
coap_binary_t * coap_new_binary(size_t size)
Returns a new binary object with at least size bytes storage allocated.
coap_bin_const_t * coap_new_bin_const(const uint8_t *data, size_t size)
Take the specified byte array (text) and create a coap_bin_const_t * Returns a new const binary objec...
void coap_delete_binary(coap_binary_t *s)
Deletes the given coap_binary_t object and releases any memory allocated.
#define coap_binary_equal(binary1, binary2)
Compares the two binary data for equality.
#define coap_string_equal(string1, string2)
Compares the two strings for equality.
void coap_delete_string(coap_string_t *s)
Deletes the given string and releases any memory allocated.
int coap_tcp_is_supported(void)
Check whether TCP is available.
int coap_tls_is_supported(void)
Check whether TLS is available.
int coap_ws_is_supported(void)
Check whether WebSockets is available.
int coap_dtls_is_supported(void)
Check whether DTLS is available.
int coap_proxy_is_supported(void)
Check whether Proxy code is available.
int coap_wss_is_supported(void)
Check whether Secure WebSockets is available.
coap_string_t * coap_get_uri_path(const coap_pdu_t *request)
Extract uri_path string from request PDU.
int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
int coap_uri_into_optlist(const coap_uri_t *uri, const coap_address_t *dst, coap_optlist_t **optlist_chain, int create_port_host_opt)
Takes a coap_uri_t and then adds CoAP options into the optlist_chain.
coap_string_t * coap_get_query(const coap_pdu_t *request)
Extract query string from request PDU according to escape rules in 6.5.8.
Resolved addresses information.
coap_proto_t proto
CoAP protocol to use.
coap_address_t addr
The address to connect / bind to.
coap_address_t remote
remote address and port
Multi-purpose address abstraction.
CoAP binary data definition with const data.
size_t length
length of binary data
const uint8_t * s
read-only binary data
CoAP binary data definition.
size_t length
length of binary data
The CoAP stack's global state is stored in a coap_context_t object.
char * client_sni
If not NULL, SNI to use in client TLS setup.
char * client_sni
If not NULL, SNI to use in client TLS setup.
Iterator to run through PDU options.
coap_option_num_t number
decoded option number
Representation of chained list of CoAP options to install.
size_t max_size
maximum size for token, options and payload, or zero for variable size pdu
const uint8_t * body_data
Holds ptr to re-assembled data or NULL.
coap_pdu_code_t code
request method (value 1–31) or response code (value 64-255)
coap_bin_const_t actual_token
Actual token in pdu.
coap_mid_t mid
message id, if any, in regular host byte order
size_t used_size
used bytes of storage for token, options and payload
coap_session_t * session
Session responsible for PDU or NULL.
coap_pdu_type_t type
message type
int track_client_session
If 1, track individual connections to upstream server, else 0 for all clients to be multiplexed over ...
coap_proxy_server_t * entry
Set of servers to connect to.
coap_proxy_t type
The proxy type and option controlling bits (if old type used, will get mapped into new + bits.
unsigned int idle_timeout_secs
Proxy upstream session idle timeout (0 is no timeout).
size_t next_entry
Next server to use (% entry_count).
size_t entry_count
The number of servers in entry list.
coap_dtls_pki_t * dtls_pki
PKI configuration to use if not NULL.
coap_oscore_conf_t * oscore_conf
OSCORE configuration if not NULL.
coap_uri_t uri
host and port define the server, scheme method
coap_dtls_cpsk_t * dtls_cpsk
PSK configuration to use if not NULL.
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
coap_addr_tuple_t addr_info
remote/local address info
coap_proto_t proto
protocol used
coap_response_t last_con_handler_res
The result of calling the response handler of the last CON.
coap_context_t * context
session's context
CoAP string data definition with const data.
const uint8_t * s
read-only string data
size_t length
length of string
CoAP string data definition.
Representation of parsed URI.
enum coap_uri_scheme_t scheme
The parsed scheme specifier.
uint16_t port
The port in host byte order.
coap_str_const_t host
The host part of the URI.