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 5.02 gateway issue\n");
148 coap_proxy_del_req(proxy_entry, proxy_req);
157 for (i = 0; i < context->proxy_list_count; i++) {
160 (
void *)&context->proxy_list[i]);
161 coap_proxy_cleanup_entry(&context->proxy_list[i], 0);
168 if (proxy_entry && proxy_entry->ongoing) {
172 LL_FOREACH(proxy_entry->ongoing->lg_crcv, lg_crcv) {
192 for (i = 0; i < context->proxy_list_count; i++) {
195 if (coap_proxy_check_observe(proxy_entry))
198 if (proxy_entry->ongoing && proxy_entry->idle_timeout_ticks) {
199 if (proxy_entry->last_used + proxy_entry->idle_timeout_ticks <= now) {
201 if (coap_proxy_remove_association(proxy_entry->ongoing, 0))
204 if (*tim_rem > proxy_entry->last_used + proxy_entry->idle_timeout_ticks - now) {
205 *tim_rem = proxy_entry->last_used + proxy_entry->idle_timeout_ticks - now;
215coap_get_uri_proxy_scheme_info(
const coap_pdu_t *request,
223 strncasecmp(opt_val,
"coaps+tcp", 9) == 0) {
226 }
else if (opt_len == 8 &&
227 strncasecmp(opt_val,
"coap+tcp", 8) == 0) {
230 }
else if (opt_len == 5 &&
231 strncasecmp(opt_val,
"coaps", 5) == 0) {
234 }
else if (opt_len == 4 &&
235 strncasecmp(opt_val,
"coap", 4) == 0) {
238 }
else if (opt_len == 7 &&
239 strncasecmp(opt_val,
"coap+ws", 7) == 0) {
242 }
else if (opt_len == 8 &&
243 strncasecmp(opt_val,
"coaps+ws", 8) == 0) {
248 opt_len, opt_len, opt_val);
290 coap_log_warn(
"coap+tcp URI scheme not supported for proxy\n");
296 coap_log_warn(
"coaps+tcp URI scheme not supported for proxy\n");
302 coap_log_warn(
"coap+ws URI scheme not supported for proxy\n");
308 coap_log_warn(
"coaps+ws URI scheme not supported for proxy\n");
328 size_t proxy_list_count = session->
context->proxy_list_count;
333 *proxy_entry_created = 0;
339 if (session->proxy_entry) {
340 for (i = 0; i < proxy_list_count; i++) {
341 if (&proxy_list[i] == session->proxy_entry) {
342 if (session->proxy_entry->ongoing) {
343 memset(server_use, 0,
sizeof(*server_use));
344 return session->proxy_entry;
356 memcpy(server_use, &server_list->
entry[server_list->
next_entry],
sizeof(*server_use));
358 memset(server_use, 0,
sizeof(*server_use));
361 switch (server_list->
type) {
376 if (!coap_get_uri_proxy_scheme_info(request, proxy_scheme, &server_use->
uri)) {
391 &server_use->
uri) < 0) {
399 if (!(proxy_scheme || proxy_uri)) {
421 for (i = 0; i < proxy_list_count; i++) {
423 proxy_list[i].uri.port == server_use->
uri.
port &&
424 proxy_list[i].uri.scheme == server_use->
uri.
scheme) {
427 return &proxy_list[i];
429 if (proxy_list[i].incoming == session) {
431 return &proxy_list[i];
440 if (new_proxy_list == NULL) {
444 session->
context->proxy_list = proxy_list = new_proxy_list;
445 memset(&proxy_list[i], 0,
sizeof(proxy_list[i]));
448 proxy_list[i].uri = server_use->
uri;
451 if (!proxy_list[i].uri_host_keep) {
455 memcpy(proxy_list[i].uri_host_keep, server_use->
uri.
host.
s,
457 proxy_list[i].uri.host.s = proxy_list[i].uri_host_keep;
459 proxy_list[i].uri.path.s = NULL;
460 proxy_list[i].uri.path.length = 0;
461 proxy_list[i].uri.query.s = NULL;
462 proxy_list[i].uri.query.length = 0;
465 proxy_list[i].incoming = session;
467 *proxy_entry_created = 1;
468 session->
context->proxy_list_count++;
471 session->proxy_entry = &proxy_list[i];
472 return &proxy_list[i];
476coap_proxy_remove_association(
coap_session_t *session,
int send_failure) {
480 size_t proxy_list_count = session->
context->proxy_list_count;
482 for (i = 0; i < proxy_list_count; i++) {
484 coap_proxy_req_t *proxy_req;
488 LL_FOREACH(proxy_entry->proxy_req, proxy_req) {
489 if (proxy_req->incoming == session) {
490 coap_proxy_del_req(proxy_entry, proxy_req);
494 if (proxy_entry->incoming == session) {
498 proxy_entry->ongoing = NULL;
504 if (proxy_entry->ongoing == session) {
507 coap_proxy_cleanup_entry(proxy_entry, send_failure);
508 ongoing = proxy_entry->ongoing;
509 coap_log_debug(
"* %s: proxy_entry %p released (rem count = %zd)\n",
512 session->
context->proxy_list_count - 1);
513 if (proxy_list_count-i > 1) {
514 memmove(&proxy_list[i],
516 (proxy_list_count-i-1) *
sizeof(proxy_list[0]));
518 session->
context->proxy_list_count--;
537 static char client_sni[256];
539 int proxy_entry_created;
541 proxy_entry = coap_proxy_get_session(session, request, response, server_list,
542 &server_use, &proxy_entry_created);
548 if (!proxy_entry->ongoing) {
562 if (info_list == NULL) {
564 coap_proxy_remove_association(session, 0);
567 proto = info_list->
proto;
568 memcpy(&dst, &info_list->
addr,
sizeof(dst));
571#if COAP_AF_UNIX_SUPPORT
580 "/tmp/coap-pr-cl-%" PRIu64, (uint64_t)now);
583 fprintf(stderr,
"coap_address_set_unix_domain: %s: failed\n",
589 local_addr = &bind_addr;
593 snprintf(client_sni,
sizeof(client_sni),
"%*.*s", (
int)server_use.
uri.
host.
length,
600#if COAP_OSCORE_SUPPORT
602 proxy_entry->ongoing =
607 proxy_entry->ongoing =
609#if COAP_OSCORE_SUPPORT
616#if COAP_OSCORE_SUPPORT
620 proxy_entry->ongoing =
625 proxy_entry->ongoing =
629 coap_log_warn(
"Proxy: (D)TLS not configured for secure session\n");
636 proxy_entry->ongoing =
641 proxy_entry->ongoing =
646 proxy_entry->ongoing =
649#if COAP_OSCORE_SUPPORT
660 if (proxy_entry->ongoing == NULL) {
662 coap_proxy_remove_association(session, 0);
665 if (proxy_entry_created) {
666 coap_log_debug(
"* %s: proxy_entry %p created (tot count = %zd)\n",
669 session->
context->proxy_list_count);
671 }
else if (proxy_entry->ongoing->session_failed) {
687static coap_proxy_req_t *
688coap_proxy_get_req(
coap_proxy_list_t *proxy_entry, coap_proxy_cache_t *proxy_cache,
690 coap_proxy_req_t *proxy_req;
692 LL_FOREACH(proxy_entry->proxy_req, proxy_req) {
693 if (proxy_req->incoming == session && proxy_req->proxy_cache == proxy_cache) {
708 coap_proxy_req_t *proxy_req,
int replace_mid,
709 int remove_observe) {
719 if (remove_observe) {
739 resp_pdu->
mid = sent->
mid;
741 proxy_req->mid = resp_pdu->
mid;
744 uint16_t media_type = 0;
752 assert(size == total);
756 coap_log_debug(
"coap_proxy_call_response_handler: copy data error\n");
779 media_type, maxage, etag, body->
length,
781 coap_proxy_free_response_data,
783 coap_log_debug(
"coap_proxy_call_response_handler: add data error\n");
788 session->
context->proxy_response_handler(session,
791 proxy_req->cache_key),
799 if (fwd_pdu != resp_pdu) {
822 ret = coap_proxy_forward_request_lkd(session,
857 coap_proxy_req_t *proxy_req = NULL;
865 coap_proxy_cache_t *proxy_cache = NULL;
868 proxy_entry = coap_proxy_get_ongoing_session(session, request, response,
874 coap_proxy_log_entry(session, request, NULL,
"req");
877 if (obs_opt && session->
context->proxy_response_handler) {
882 coap_proxy_ignore_options,
883 sizeof(coap_proxy_ignore_options)/
sizeof(coap_proxy_ignore_options[0]));
888 PROXY_CACHE_FIND(proxy_entry->rsp_cache, cache_key_l, proxy_cache);
893 proxy_req = coap_proxy_get_req(proxy_entry, proxy_cache, session);
904 if (proxy_req->doing_observe) {
905 assert(proxy_req->incoming->ref_proxy_subs);
906 proxy_req->incoming->ref_proxy_subs--;
907 proxy_req->doing_observe = 0;
909 if (proxy_entry->proxy_req && !proxy_entry->proxy_req->next &&
910 proxy_req->token_used) {
913 coap_log_debug(
"coap_proxy_forward_request: Using coap_cancel_observe() to do Proxy OBSERVE cancellation\n");
915 memcpy(&tmp.
s, &proxy_req->token_used->s,
sizeof(tmp.
s));
916 tmp.
length = proxy_req->token_used->length;
922 goto return_cached_info;
929 coap_proxy_del_req(proxy_entry, proxy_req);
933 goto return_cached_info;
940 coap_proxy_del_req(proxy_entry, proxy_req);
944 goto return_cached_info;
952 if (proxy_req == NULL) {
955 memset(proxy_req, 0,
sizeof(coap_proxy_req_t));
956 LL_PREPEND(proxy_entry->proxy_req, proxy_req);
959 proxy_req->resource = resource;
960 proxy_req->incoming = session;
961 proxy_req->cache_key = cache_key;
962 proxy_req->proxy_cache = proxy_cache;
964 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"add");
975 if (proxy_req->token_used == NULL) {
978 goto return_cached_info;
985 if (proxy_req->token_used == NULL) {
992 switch (server_list->
type) {
1018 switch (opt_iter.
number) {
1076 assert(size == total);
1086 memcpy(body_data->
s, data, size);
1088 coap_proxy_release_body_data, body_data)) {
1094 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"fwd");
1114 if (obs_opt && !proxy_req->doing_observe) {
1121 proxy_req->doing_observe = 1;
1122 proxy_req->incoming->ref_proxy_subs++;
1128 coap_proxy_log_entry(session, request, &proxy_cache->rsp_pdu->actual_token,
"rspc");
1129 coap_proxy_call_response_handler(session, request, proxy_cache->rsp_pdu,
1130 &r_token, proxy_req, 1, obs_opt ? 0 : 1);
1132 coap_proxy_del_req(proxy_entry, proxy_req);
1141 size_t proxy_list_count = ongoing->
context->proxy_list_count;
1145 coap_proxy_req_t *proxy_req;
1147 for (i = 0; i < proxy_list_count; i++) {
1148 proxy_entry = &proxy_list[i];
1149 if (proxy_entry->ongoing == ongoing) {
1150 LL_FOREACH(proxy_entry->proxy_req, proxy_req) {
1154 *u_proxy_entry = proxy_entry;
1164 scratch[0] =
'\000';
1165 for (i = 0; i < rcv_token.
length; i++) {
1166 size = strlen(scratch);
1167 snprintf(&scratch[size],
sizeof(scratch)-size,
1168 "%02x", rcv_token.
s[i]);
1171 for (i = 0; i < proxy_list_count; i++) {
1172 proxy_entry = &proxy_list[i];
1173 LL_FOREACH(proxy_entry->proxy_req, proxy_req) {
1174 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"miss");
1188 ret = coap_proxy_forward_response_lkd(session,
1202 const uint8_t *data;
1217 coap_proxy_req_t *proxy_req = NULL;
1219 proxy_req = coap_proxy_map_outgoing_request(session, received, &proxy_entry);
1220 if (!proxy_req || proxy_req->incoming->server_list) {
1221 coap_log_warn(
"Unknown proxy ongoing session response received - ignored\n");
1225 req_pdu = proxy_req->pdu;
1227 resource = proxy_req->resource;
1228 incoming = proxy_req->incoming;
1230 coap_log_debug(
"** process upstream incoming %d.%02d response:\n",
1235 assert(size == total);
1241 memcpy(body_data->
s, data, size);
1242 data = body_data->
s;
1258 coap_log_debug(
"cannot add token to ongoing proxy response PDU\n");
1267 switch (opt_iter.
number) {
1300 media_type, maxage, etag, size, data,
1301 coap_proxy_release_body_data,
1308 *cache_key = proxy_req->cache_key;
1315 if (option == NULL) {
1316 if (proxy_entry->proxy_req) {
1318 proxy_req->cache_key = NULL;
1319 coap_proxy_del_req(proxy_entry, proxy_req);
1321 }
else if (!proxy_req->doing_observe) {
1326 proxy_req->doing_observe = 1;
1327 proxy_req->incoming->ref_proxy_subs++;
1337 void *body_data, coap_proxy_req_t *proxy_req,
1349 coap_proxy_cache_t *proxy_cache;
1355 if (proxy_req->proxy_cache) {
1357 proxy_cache = proxy_req->proxy_cache;
1360 if (proxy_cache == NULL) {
1363 memset(proxy_cache, 0,
sizeof(coap_proxy_cache_t));
1366 coap_proxy_ignore_options,
1367 sizeof(coap_proxy_ignore_options)/
sizeof(coap_proxy_ignore_options[0]));
1372 memcpy(&proxy_cache->cache_req, cache_key_l,
1373 sizeof(proxy_cache->cache_req));
1377 proxy_req->proxy_cache = proxy_cache;
1379 PROXY_CACHE_ADD(proxy_entry->rsp_cache, proxy_cache);
1388 proxy_cache->etag = 0;
1402 LL_FOREACH(proxy_entry->proxy_req, proxy_req) {
1403 if (proxy_req->proxy_cache == proxy_cache) {
1404 if (!proxy_req->doing_observe) {
1411 proxy_req->doing_observe = 1;
1412 proxy_req->incoming->ref_proxy_subs++;
1415 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"rsp");
1417 if (coap_proxy_call_response_handler(proxy_req->incoming, proxy_req->pdu,
1428 coap_proxy_log_entry(proxy_req->incoming, proxy_req->pdu, proxy_req->token_used,
"rspn");
1430 ret = coap_proxy_call_response_handler(proxy_req->incoming, proxy_req->pdu,
1431 rcvd, &token, proxy_req, 0, 0);
1433 coap_proxy_del_req(proxy_entry, proxy_req);
1458 coap_log_err(
"coap_proxy_local_write: Unknown or Proxy resource not defined\n");
1466 coap_log_err(
"coap_proxy_local_write: Could not create response PDU\n");
1482 if (!coap_proxy_forward_request_lkd(session, pdu, response, resource,
1483 NULL, session->server_list)) {
1484 coap_log_debug(
"coap_proxy_local_write: Failed to forward PDU\n");
1499 session = coap_new_client_session_proxy_lkd(ctx, server_list);
1513#if COAP_IPV6_SUPPORT
1514 remote.
s = (
const uint8_t *)
"::1";
1515#elif COAP_IPV4_SUPPORT
1516 remote.
s = (
const uint8_t *)
"127.0.0.1";
1518 coap_log_warn(
"coap_new_client_session_proxy: No IPv4 or IPv6 support\n");
1521 remote.
length = strlen((
const char *)remote.
s);
1528 coap_log_warn(
"coap_new_client_session_proxy: Unable to resolve IP address\n");
1535 session->server_list = server_list;
1543 coap_mid_t mid, coap_proxy_subs_delete_t type) {
1548 for (i = 0; i < context->proxy_list_count; i++) {
1550 coap_proxy_req_t *proxy_req, *treq;
1552 LL_FOREACH_SAFE(proxy_entry->proxy_req, proxy_req, treq) {
1553 if (proxy_req->incoming == session) {
1559 case COAP_PROXY_SUBS_ALL:
1562 case COAP_PROXY_SUBS_TOKEN:
1566 case COAP_PROXY_SUBS_MID:
1567 if (proxy_req->mid == mid)
1574 if (match && proxy_entry->proxy_req && ! proxy_entry->proxy_req->next &&
1575 proxy_req->token_used) {
1578 coap_log_debug(
"coap_delete_proxy_subscriber: Using coap_cancel_observe() to do Proxy OBSERVE cancellation\n");
1580 memcpy(&tmp.
s, &proxy_req->token_used->s,
sizeof(tmp.
s));
1581 tmp.
length = proxy_req->token_used->length;
1584 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.
coap_addr_info_t * coap_resolve_address_info(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...
@ COAP_RESOLVE_TYPE_REMOTE
remote side of session
#define COAP_UNIX_PATH_MAX
struct coap_proxy_list_t coap_proxy_list_t
Proxy information.
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_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_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.
int coap_add_data_large_response_lkd(coap_resource_t *resource, coap_session_t *session, const coap_pdu_t *request, coap_pdu_t *response, const coap_string_t *query, uint16_t media_type, int maxage, uint64_t etag, size_t length, const uint8_t *data, coap_release_large_data_t release_func, void *app_ptr)
Associates given data with the response pdu that is passed as fourth parameter.
int coap_add_data_large_request_lkd(coap_session_t *session, coap_pdu_t *pdu, size_t length, const uint8_t *data, coap_release_large_data_t release_func, void *app_ptr)
Associates given data with the pdu that is passed as second parameter.
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.
void coap_ticks(coap_tick_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_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.
#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(uint16_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 ...
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_oscore_psk_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)
Creates a new client session to the designated server with PSK credentials as well as protecting the ...
coap_session_t * coap_new_client_session_oscore_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)
Creates a new client session to the designated server, protecting the data using OSCORE.
coap_session_t * coap_new_client_session_oscore_pki_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)
Creates a new client session to the designated server with PKI credentials as well as protecting the ...
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.
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_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)
Duplicate an existing 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)
#define COAP_OPTION_URI_HOST
coap_pdu_code_t coap_pdu_get_code(const coap_pdu_t *pdu)
Gets the PDU code associated with pdu.
#define COAP_OPTION_BLOCK2
#define COAP_OPTION_CONTENT_FORMAT
#define COAP_OPTION_SIZE2
#define COAP_OPTION_BLOCK1
#define COAP_OPTION_Q_BLOCK1
#define COAP_OPTION_PROXY_SCHEME
#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.
coap_pdu_code_t
Set of codes available for a PDU.
#define COAP_OPTION_OSCORE
#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 COAP_OPTION_Q_BLOCK2
#define COAPS_DEFAULT_PORT
#define COAP_OPTION_URI_PORT
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.
#define COAP_OPTION_MAXAGE
#define COAP_OPTION_PROXY_URI
#define COAP_OPTION_OBSERVE
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_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.
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_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_REVERSE_STRIP
Act as a reverse proxy, strip out proxy options.
@ COAP_PROXY_FORWARD_DYNAMIC
Act as a forward-dynamic proxy using the request's Proxy-Uri or Proxy-Scheme options to determine ser...
@ COAP_PROXY_REVERSE
Act as a reverse proxy.
@ COAP_PROXY_FORWARD_STATIC
Act as a forward-static proxy.
@ COAP_PROXY_FORWARD_DYNAMIC_STRIP
Act as a forward-dynamic proxy, strip out proxy options.
@ COAP_PROXY_FORWARD_STATIC_STRIP
Act as a forward-static proxy, strip out proxy options.
coap_session_t * coap_new_client_session_psk2_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)
Creates a new client session to the designated server with PSK credentials.
int coap_session_reconnect(coap_session_t *session)
Close the current session (if not already closed) and reconnect to server (client session only).
coap_session_t * coap_new_client_session_pki_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)
Creates a new client session to the designated server with PKI credentials.
coap_session_t * coap_new_client_session_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto)
Creates a new client session to the designated server.
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.
#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_cancel_observe_lkd(coap_session_t *session, coap_binary_t *token, coap_pdu_type_t message_type)
Cancel an observe that is being tracked by the client large receive logic.
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.
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.
coap_resource_t * proxy_uri_resource
can be used for handling proxy URI resources
coap_resource_t * unknown_resource
can be used for handling unknown resources
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.
Structure to hold large body (many blocks) client receive information.
uint8_t observe_set
Set if this is an observe receive PDU.
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
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.
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 resource that can be attached to coap_context_t.
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
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.