14 #define min(a,b) ((a) < (b) ? (a) : (b))
68 size_t start, want, avail;
73 start = block->
num << (block->
szx + 4);
74 if (block->
num != 0 && data_length <= start) {
81 want = (size_t)1 << (block->
szx + 4);
85 block->
m = want < data_length - start;
92 if (data_length - start <= avail) {
103 "not enough space, even the smallest block does not fit\n");
106 newBlockSize =
coap_flsll((
long long)avail) - 5;
108 "decrease block size for %zu to %d\n", avail, newBlockSize);
110 block->
szx = newBlockSize;
112 block->
num <<= szx - block->
szx;
128 unsigned int block_num,
unsigned char block_szx) {
130 start = block_num << (block_szx + 4);
136 min(len - start, ((
size_t)1 << (block_szx + 4))),
152 unsigned char buf[4];
154 int block2_requested = 0;
162 block2_requested = 1;
163 if (block2.
num != 0 && length <= (block2.
num << (block2.
szx + 4))) {
166 length >> (block2.
szx + 4));
175 memset(etag, 0,
sizeof(etag));
190 if (block2_requested) {
250 uint8_t block_mode) {
264 const uint8_t *b,
size_t blen) {
267 return alen == blen && memcmp(a, b, blen) == 0;
269 return alen == blen && memcmp(a+bias, b+bias, 4) == 0;
274 const uint8_t *b,
size_t blen) {
275 return alen == blen && (alen == 0 || memcmp(a, b, alen) == 0);
289 "** %s: coap_cancel_observe: COAP_BLOCK_USE_LIBCOAP not enabled\n",
294 LL_FOREACH(session->
lg_crcv, cq) {
349 int have_block_defined = 0;
357 "** %s: coap_add_data_large: COAP_BLOCK_USE_LIBCOAP not enabled\n",
363 #define MAX_BLK_LEN (((1 << 20) - 1) * (1 << (6 + 4)))
367 "Size of large buffer restricted to 0x%x bytes\n",
MAX_BLK_LEN);
377 LL_FOREACH_SAFE(session->
lg_xmit, lg_xmit, q) {
382 LL_DELETE(session->
lg_xmit, lg_xmit);
398 LL_FOREACH_SAFE(session->
lg_xmit, lg_xmit, q) {
403 LL_DELETE(session->
lg_xmit, lg_xmit);
414 blk_size =
coap_flsll((
long long)avail) - 4 - 1;
418 if (block.
szx < blk_size)
419 blk_size = block.
szx;
420 have_block_defined = 1;
423 if (avail < 16 && ((ssize_t)length > avail || have_block_defined)) {
426 "not enough space, even the smallest block does not fit\n");
430 chunk = (size_t)1 << (blk_size + 4);
431 if (have_block_defined && block.
num != 0) {
441 if (length >= block.
num * chunk) {
443 if (chunk > length - block.
num * chunk)
444 rem = length - block.
num * chunk;
449 release_func(session, app_ptr);
451 else if ((have_block_defined && length > chunk) || (ssize_t)length > avail) {
470 lg_xmit->blk_size = blk_size;
471 lg_xmit->option = option;
472 lg_xmit->data = data;
473 lg_xmit->length = length;
475 lg_xmit->release_func = release_func;
476 lg_xmit->last_payload = 0;
477 lg_xmit->last_used = 0;
478 lg_xmit->app_ptr = app_ptr;
482 if (!lg_xmit->b.b1.app_token)
488 lg_xmit->b.b1.count = 1;
489 token = ((++session->
tx_token) & 0xffffffff) +
490 ((uint64_t)lg_xmit->b.b1.count << 32);
491 memset(lg_xmit->b.b1.token, 0,
sizeof(lg_xmit->b.b1.token));
493 sizeof(token), token);
501 (
unsigned int)length),
509 lg_xmit->b.b2.resource = resource;
512 if (lg_xmit->b.b2.query) {
513 memcpy(lg_xmit->b.b2.query->s, query->
s, query->
length);
517 lg_xmit->b.b2.query = NULL;
519 lg_xmit->b.b2.etag = etag;
527 lg_xmit->b.b2.maxage_expire = 0;
532 (
unsigned int)length),
546 block.
m = ((block.
num + 1) * chunk) < lg_xmit->length;
550 (block.
num << 4) | (block.
m << 3) | lg_xmit->blk_size),
554 memcpy(&lg_xmit->pdu, pdu,
sizeof(lg_xmit->pdu));
556 8 + lg_xmit->pdu.used_size + lg_xmit->pdu.hdr_size);
557 if (!lg_xmit->pdu.token)
560 lg_xmit->pdu.alloc_size = 8 + lg_xmit->pdu.used_size +
561 lg_xmit->pdu.hdr_size;
562 lg_xmit->pdu.token += lg_xmit->pdu.hdr_size;
563 memcpy(lg_xmit->pdu.token, pdu->
token, lg_xmit->pdu.used_size);
565 lg_xmit->pdu.data = lg_xmit->pdu.token + (pdu->
data - pdu->
token);
571 if (avail < (ssize_t)chunk) {
575 "not enough space, even the smallest block does not fit\n");
578 blk_size =
coap_flsll((
long long)avail) - 4 - 1;
579 block.
num = block.
num << (lg_xmit->blk_size - blk_size);
580 lg_xmit->blk_size = blk_size;
581 chunk = (size_t)1 << (lg_xmit->blk_size + 4);
585 (block.
num << 4) | (block.
m << 3) | lg_xmit->blk_size),
590 if (chunk > lg_xmit->length - block.
num * chunk)
591 rem = lg_xmit->length - block.
num * chunk;
595 lg_xmit->last_block = -1;
598 LL_PREPEND(session->
lg_xmit,lg_xmit);
602 if (have_block_defined) {
606 (0 << 4) | (0 << 3) | blk_size), buf);
613 release_func(session, app_ptr);
622 release_func(session, app_ptr);
634 0, length, data, release_func, app_ptr);
651 unsigned char buf[4];
653 int block_requested = 0;
663 if (block.
num != 0 && length <= (block.
num << (block.
szx + 4))) {
666 length >> (block.
szx + 4));
684 if (block_requested) {
705 maxage, etag, length, data,
706 release_func, app_ptr)) {
718 etag, length, data, release_func,
740 LL_FOREACH_SAFE(session->
lg_crcv, p, q) {
744 LL_DELETE(session->
lg_crcv, p);
749 if (tim_rem > p->
last_used + partial_timeout - now)
750 tim_rem = p->
last_used + partial_timeout - now;
760 for (i = 0; i < rec_blocks->
used; i++) {
761 if (block_num < rec_blocks->range[i].begin)
763 if (block_num <= rec_blocks->range[i].end)
774 for (i = 0; i < rec_blocks->
used; i++) {
775 if (block < rec_blocks->range[i].begin)
777 if (block < rec_blocks->range[i].end)
781 if (block + 1 < total_blocks)
794 LL_FOREACH_SAFE(session->
lg_srcv, p, q) {
797 LL_DELETE(session->
lg_srcv, p);
802 if (tim_rem > p->
last_used + partial_timeout - now)
803 tim_rem = p->
last_used + partial_timeout - now;
823 memcpy(&lg_crcv->
pdu, pdu,
sizeof(lg_crcv->
pdu));
840 memset(lg_crcv->
token, 0,
sizeof(lg_crcv->
token));
913 uint32_t *count, uint32_t max_count) {
916 for (i = 0; i < *count && *count < max_count; i++) {
917 if (num == out_blocks[i])
919 else if (num < out_blocks[i]) {
921 memmove(&out_blocks[i], &out_blocks[i+1], *count - i -1);
927 if (*count < max_count) {
958 uint16_t block_opt = 0;
959 uint32_t out_blocks[1];
960 const char *error_phrase;
965 LL_FOREACH(session->
lg_xmit, p) {
970 uint32_t request_cnt, i;
998 chunk = (size_t)1 << (p->
blk_size + 4);
1001 "found Block option, block size is %zu, block nr. %u, M %d\n",
1002 (
size_t)1 << (block.
szx + 4), block.
num, block.
m);
1004 if ((p->
offset + chunk) % ((
size_t)1 << (block.
szx + 4)) == 0) {
1009 block.
num = (uint32_t)(((p->
offset + chunk) >> (block.
szx + 4)) - 1);
1011 chunk = (size_t)1 << (p->
blk_size + 4);
1014 "new Block size is %u, block number %u completed\n",
1015 1 << (block.
szx + 4), block.
num);
1018 "ignoring request to increase Block size, "
1019 "next block is not aligned on requested block size "
1020 "boundary. (%zu x %u mod %u = %zu (which is not 0)\n",
1022 (1 << (block.
szx + 4)),
1023 (p->
offset + chunk) % ((
size_t)1 << (block.
szx + 4)));
1039 sizeof(
"Changing blocksize during request invalid")-1,
1040 (
const uint8_t *)
"Changing blocksize during request invalid");
1047 if (request_cnt == 0) {
1055 for (i = 0; i < request_cnt; i++) {
1058 block.
num = out_blocks[i];
1061 if (i + 1 < request_cnt) {
1069 pdu->
token, &drop_options);
1088 goto internal_issue;
1099 ((p->
offset + chunk < p->length) << 3) |
1102 goto internal_issue;
1123 goto internal_issue;
1132 goto internal_issue;
1134 if (i + 1 < request_cnt) {
1138 goto skip_app_handler;
1143 goto skip_app_handler;
1154 (
const uint8_t *)error_phrase);
1163 rec_blocks->
retry = 0;
1165 for (i = 0; i < rec_blocks->
used; i++) {
1166 if (block_num >= rec_blocks->
range[i].
begin &&
1167 block_num <= rec_blocks->range[i].end)
1170 if (block_num < rec_blocks->range[i].begin) {
1171 if (block_num + 1 == rec_blocks->
range[i].
begin) {
1179 memmove(&rec_blocks->
range[i+1], &rec_blocks->
range[i],
1180 (rec_blocks->
used - i) * sizeof (rec_blocks->
range[0]));
1186 if (block_num == rec_blocks->
range[i].
end + 1) {
1187 rec_blocks->
range[i].
end = block_num;
1188 if (i + 1 < rec_blocks->
used) {
1189 if (rec_blocks->
range[i+1].
begin == block_num + 1) {
1192 if (i+2 < rec_blocks->
used) {
1193 memmove (&rec_blocks->
range[i+1], &rec_blocks->
range[i+2],
1194 (rec_blocks->
used - (i+2)) * sizeof (rec_blocks->
range[0]));
1202 if (i == rec_blocks->
used) {
1233 const uint8_t *data = NULL;
1238 uint16_t block_option = 0;
1261 offset = block.
num << (block.
szx + 4);
1263 LL_FOREACH(session->
lg_srcv, p) {
1272 if (!p && block.
num != 0) {
1277 pdu->
body_total = length + offset + (block.
m ? 1 : 0);
1280 else if (!p && !(offset == 0 && block.
m == 0)) {
1284 (
const uint8_t *)
"Memory issue");
1286 goto skip_app_handler;
1291 p->resource = resource;
1295 p->content_format = fmt;
1296 p->total_len = total;
1297 p->amount_so_far = length;
1299 p->block_option = block_option;
1305 p->body_data = NULL;
1306 LL_PREPEND(session->
lg_srcv, p);
1310 coap_add_data(response,
sizeof(
"Content-Format mismatch")-1,
1311 (
const uint8_t *)
"Content-Format mismatch");
1320 size_t chunk = (size_t)1 << (block.
szx + 4);
1325 coap_add_data(response,
sizeof(
"Too many missing blocks")-1,
1326 (
const uint8_t *)
"Too many missing blocks");
1334 goto call_app_handler;
1338 (uint32_t)(p->
total_len + chunk -1)/chunk)) {
1351 goto skip_app_handler;
1353 goto skip_app_handler;
1373 h(resource, session, pdu, query, response);
1378 goto skip_app_handler;
1387 if (total > offset + length + block.
m)
1398 h(resource, session, pdu, query, response);
1406 goto skip_app_handler;
1417 goto call_app_handler;
1420 LL_DELETE(session->
lg_srcv, p);
1422 goto skip_app_handler;
1451 LL_FOREACH_SAFE(session->
lg_xmit, p, q) {
1457 size_t chunk = (size_t)1 << (p->
blk_size + 4);
1463 "found Block option, block size is %u, block nr. %u\n",
1464 1 << (block.
szx + 4), block.
num);
1466 if ((p->
offset + chunk) % ((
size_t)1 << (block.
szx + 4)) == 0) {
1471 block.
num = (uint32_t)(((p->
offset + chunk) >> (block.
szx + 4)) - 1);
1473 chunk = (size_t)1 << (p->
blk_size + 4);
1476 "new Block size is %u, block number %u completed\n",
1477 1 << (block.
szx + 4), block.
num);
1480 "next block is not aligned on requested block size boundary. "
1481 "(%zu x %u mod %u = %zu != 0)\n",
1483 (1 << (block.
szx + 4)),
1484 (p->
offset + chunk) % ((
size_t)1 << (block.
szx + 4)));
1509 size_t ltoken_length;
1511 token = (token & 0xffffffff) + ((uint64_t)(++p->
b.
b1.
count) << 32);
1521 ((p->
offset + chunk < p->length) << 3) |
1544 LL_DELETE(session->
lg_xmit, p);
1560 const uint8_t *data,
size_t offset,
size_t total)
1564 if (body_data == NULL && total) {
1567 if (body_data == NULL)
1571 if (offset + length <= total && body_data->length >= total) {
1572 memcpy(&body_data->
s[offset], data, length);
1589 memcpy(&body_data->
s[offset], data, length);
1617 int app_has_response = 0;
1620 uint16_t block_opt = 0;
1623 LL_FOREACH(session->
lg_crcv, p) {
1638 const uint8_t *data;
1641 size_t size2 = size_opt ?
1656 uint16_t fmt = fmt_opt ?
1664 chunk = (size_t)1 << (block.
szx + 4);
1665 offset = block.
num * chunk;
1666 if (size2 < (offset + length)) {
1668 size2 = offset + length + 1;
1670 size2 = offset + length;
1702 "Data body updated during receipt - new request started\n");
1720 (0 << 4) | (0 << 3) | block.
szx),
1726 goto skip_app_handler;
1742 "found Block option, block size is %u, block nr. %u\n",
1743 1 << (block.
szx + 4), block.
num);
1744 if (block.
num == 0) {
1774 (size2 + chunk -1) / chunk)) {
1796 ((block.
num + 1) << 4) |
1797 (block.
m << 3) | block.
szx),
1804 goto skip_app_handler;
1810 goto call_app_handler;
1838 app_has_response = 1;
1848 goto skip_app_handler;
1858 if(size2 > block.
num*chunk + length + block.
m)
1875 app_has_response = 1;
1914 if (block.
num != 0) {
1917 const uint8_t *data;
1918 size_t chunk = (size_t)1 << (block.
szx + 4);
1930 LL_PREPEND(session->
lg_crcv, lg_crcv);
1937 return app_has_response;
1953 if (response->
code == 0)
1955 LL_FOREACH(session->
lg_xmit, lg_xmit) {
static int add_block_send(uint32_t num, uint32_t *out_blocks, uint32_t *count, uint32_t max_count)
COAP_STATIC_INLINE int full_match(const uint8_t *a, size_t alen, const uint8_t *b, size_t blen)
static int check_all_blocks_in(coap_rblock_t *rec_blocks, size_t total_blocks)
static int update_received_blocks(coap_rblock_t *rec_blocks, uint32_t block_num)
static int check_if_received_block(coap_rblock_t *rec_blocks, uint32_t block_num)
COAP_STATIC_INLINE int block_token_match(const uint8_t *a, size_t alen, const uint8_t *b, size_t blen)
unsigned char coap_key_t[4]
#define coap_hash(String, Length, Result)
Pulls together all the internal only header files.
int coap_flsll(long long i)
coap_tick_t coap_block_check_lg_srcv_timeouts(coap_session_t *session, coap_tick_t now)
void coap_block_delete_lg_srcv(coap_session_t *session, coap_lg_srcv_t *lg_srcv)
void coap_block_delete_lg_crcv(coap_session_t *session, coap_lg_crcv_t *lg_crcv)
int coap_handle_response_get_block(coap_context_t *context, coap_session_t *session, coap_pdu_t *sent, coap_pdu_t *rcvd, coap_recurse_t recursive)
void coap_block_delete_lg_xmit(coap_session_t *session, coap_lg_xmit_t *lg_xmit)
void coap_check_code_lg_xmit(coap_session_t *session, coap_pdu_t *response, coap_resource_t *resource, coap_string_t *query)
The function checks that the code in a newly formed lg_xmit created by coap_add_data_large_response()...
int coap_add_data_large_internal(coap_session_t *session, coap_pdu_t *pdu, coap_resource_t *resource, const coap_string_t *query, int maxage, uint64_t etag, size_t length, const uint8_t *data, coap_release_large_data_t release_func, void *app_ptr)
The function that does all the work for the coap_add_data_large*() functions.
coap_tick_t coap_block_check_lg_crcv_timeouts(coap_session_t *session, coap_tick_t now)
int coap_handle_request_send_block(coap_session_t *session, coap_pdu_t *pdu, coap_pdu_t *response, coap_resource_t *resource, coap_string_t *query)
int coap_handle_request_put_block(coap_context_t *context, coap_session_t *session, coap_pdu_t *pdu, coap_pdu_t *response, coap_resource_t *resource, coap_string_t *uri_path, coap_opt_t *observe, coap_string_t *query, coap_method_handler_t h, int *added_block)
coap_lg_crcv_t * coap_block_new_lg_crcv(coap_session_t *session, coap_pdu_t *pdu)
int coap_handle_response_send_block(coap_session_t *session, coap_pdu_t *rcvd)
void coap_context_set_block_mode(coap_context_t *context, uint8_t block_mode)
Set the context level CoAP block handling bits for handling RFC7959.
int coap_add_data_large_request(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.
#define COAP_OPT_BLOCK_SZX(opt)
Returns the value of the SZX-field of a Block option opt.
#define COAP_BLOCK_SINGLE_BODY
int coap_add_block(coap_pdu_t *pdu, size_t len, const uint8_t *data, unsigned int block_num, unsigned char block_szx)
Adds the block_num block of size 1 << (block_szx + 4) from source data to pdu.
coap_binary_t * coap_block_build_body(coap_binary_t *body_data, size_t length, const uint8_t *data, size_t offset, size_t total)
Re-assemble payloads into a body.
void(* coap_release_large_data_t)(coap_session_t *session, void *app_ptr)
Callback handler for de-allocating the data based on app_ptr provided to coap_add_data_large_*() func...
void coap_add_data_blocked_response(const coap_pdu_t *request, coap_pdu_t *response, uint16_t media_type, int maxage, size_t length, const uint8_t *data)
Adds the appropriate part of data to the response pdu.
#define COAP_OPT_BLOCK_MORE(opt)
Returns the value of the More-bit of a Block option opt.
unsigned int coap_opt_block_num(const coap_opt_t *block_opt)
Returns the value of field num in the given block option block_opt.
int coap_get_block(const coap_pdu_t *pdu, coap_option_num_t number, coap_block_t *block)
Initializes block from pdu.
#define COAP_OPT_BLOCK_LAST(opt)
Returns the value of the least significant byte of a Block option opt.
int coap_write_block_opt(coap_block_t *block, coap_option_num_t number, coap_pdu_t *pdu, size_t data_length)
Writes a block option of type number to message pdu.
int coap_cancel_observe(coap_session_t *session, coap_binary_t *token, coap_pdu_type_t type)
Cancel an observe that is being tracked by the client large receive logic.
int coap_add_data_large_response(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.
#define COAP_BLOCK_USE_LIBCOAP
#define COAP_EXCHANGE_LIFETIME(s)
The EXCHANGE_LIFETIME definition for the session (s).
void coap_ticks(coap_tick_t *t)
Sets t to the internal time with COAP_TICKS_PER_SECOND resolution.
time_t coap_time_t
CoAP time in seconds since epoch.
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
coap_time_t coap_ticks_to_rt(coap_tick_t t)
Helper function that converts coap ticks to wallclock time.
void(* coap_method_handler_t)(coap_resource_t *, coap_session_t *, const coap_pdu_t *, const coap_string_t *, coap_pdu_t *)
Definition of message handler function.
coap_mid_t coap_send_internal(coap_session_t *session, coap_pdu_t *pdu)
Sends a CoAP message to given peer.
int coap_handle_event(coap_context_t *context, coap_event_t event, coap_session_t *session)
Invokes the event handler of context for the given event and data.
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.
unsigned int coap_encode_var_safe8(uint8_t *buf, size_t length, uint64_t val)
Encodes multiple-length byte sequences.
#define COAP_EVENT_PARTIAL_BLOCK
BLOCK2 receive errors.
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu)
Display the contents of the specified pdu.
const char * coap_session_str(const coap_session_t *session)
Get session description.
#define coap_log(level,...)
Logging function.
#define COAP_OBSERVE_CANCEL
The value COAP_OBSERVE_CANCEL in a GET/FETCH request option COAP_OPTION_OBSERVE indicates that the ob...
coap_opt_t * coap_option_next(coap_opt_iterator_t *oi)
Updates the iterator oi to point to the next option.
uint32_t coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option.
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.
#define COAP_OPT_ALL
Pre-defined filter that includes all options.
const uint8_t * coap_opt_value(const coap_opt_t *opt)
Returns a pointer to the value 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.
int coap_option_filter_set(coap_opt_filter_t *filter, coap_option_num_t option)
Sets the corresponding entry for number in filter.
size_t coap_insert_option(coap_pdu_t *pdu, coap_option_num_t number, size_t len, const uint8_t *data)
Inserts option of given number in the pdu with the appropriate data.
int coap_remove_option(coap_pdu_t *pdu, coap_option_num_t number)
Removes (first) option of given number from the pdu.
int coap_update_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Updates token in pdu with length len and data.
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.
#define COAP_PDU_IS_REQUEST(pdu)
coap_pdu_t * coap_pdu_duplicate(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.
#define COAP_OPTION_BLOCK2
#define COAP_OPTION_CONTENT_FORMAT
#define COAP_OPTION_SIZE2
#define COAP_OPTION_BLOCK1
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)
#define COAP_OPTION_SIZE1
coap_pdu_type_t
CoAP PDU message type definitions.
#define COAP_MEDIATYPE_TEXT_PLAIN
#define COAP_OPTION_CONTENT_TYPE
size_t coap_add_option(coap_pdu_t *pdu, coap_option_num_t number, size_t len, const uint8_t *data)
Adds option of given number to pdu that is passed as first parameter.
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.
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.
const char * coap_response_phrase(unsigned char code)
Returns a human-readable response phrase for the specified CoAP response code.
#define COAP_OPTION_MAXAGE
#define COAP_OPTION_OBSERVE
int coap_add_data(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds given data to the pdu that is passed as first parameter.
void coap_session_new_token(coap_session_t *session, size_t *len, uint8_t *data)
Creates a new token for use.
coap_string_t * coap_new_string(size_t size)
Returns a new string object with at least size+1 bytes storage allocated.
void coap_delete_str_const(coap_str_const_t *s)
Deletes the given const string and releases any memory allocated.
void coap_delete_binary(coap_binary_t *s)
Deletes the given coap_binary_t object and releases any memory allocated.
#define coap_string_equal(string1, string2)
Compares the two strings for equality.
coap_binary_t * coap_new_binary(size_t size)
Returns a new binary object with at least size bytes storage allocated.
coap_str_const_t * coap_new_str_const(const uint8_t *data, size_t size)
Returns a new const string object with at least size+1 bytes storage allocated, and the provided data...
void coap_delete_string(coap_string_t *s)
Deletes the given string and releases any memory allocated.
coap_binary_t * coap_resize_binary(coap_binary_t *s, size_t size)
Resizes the given coap_binary_t object.
#define COAP_STATIC_INLINE
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().
uint16_t coap_option_num_t
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
CoAP binary data definition.
size_t length
length of binary data
Structure of Block options.
unsigned int num
block number
unsigned int szx
block size
unsigned int m
1 if more blocks follow, 0 otherwise
The CoAP stack's global state is stored in a coap_context_t object.
uint64_t etag
Next ETag to use.
coap_response_handler_t response_handler
coap_resource_t * proxy_uri_resource
can be used for handling proxy URI resources
uint8_t block_mode
Zero or more COAP_BLOCK_ or'd options.
coap_resource_t * unknown_resource
can be used for handling unknown resources
size_t token_length
length of token
uint32_t count
the number of packets sent for payload
coap_binary_t * app_token
original PDU token
uint8_t token[8]
last used token
coap_string_t * query
Associated query for the resource.
coap_resource_t * resource
associated resource
coap_time_t maxage_expire
When this entry expires.
Structure to hold large body (many blocks) client receive information.
uint16_t block_option
Block option in use.
uint8_t etag[8]
ETag for block checking.
uint8_t etag_length
ETag length.
uint8_t last_type
Last request type (CON/NON)
uint8_t observe_length
Length of observe data.
uint8_t observe[3]
Observe data (if set) (only 24 bits)
uint8_t etag_set
Set if ETag is in receive PDU.
uint8_t initial
If set, has not been used yet.
uint8_t szx
size of individual blocks
uint16_t content_format
Content format for the set of blocks.
coap_pdu_t pdu
skeletal PDU
coap_tick_t last_used
< list of received blocks
coap_binary_t * app_token
app requesting PDU token
uint8_t token[8]
last used token
uint8_t base_token[8]
established base PDU token
size_t token_length
length of token
size_t base_token_length
length of token
coap_binary_t * body_data
Used for re-assembling entire body.
uint8_t observe_set
Set if this is an observe receive PDU.
size_t total_len
Length as indicated by SIZE2 option.
Structure to hold large body (many blocks) server receive information.
coap_mid_t last_mid
Last received mid for this set of packets.
uint8_t last_token[8]
< list of received blocks
size_t total_len
Length as indicated by SIZE1 option.
uint8_t observe_length
Length of observe data.
coap_rblock_t rec_blocks
set to uri_path if unknown resource
coap_binary_t * body_data
Used for re-assembling entire body.
coap_resource_t * resource
associated resource
size_t last_token_length
length of token
uint8_t observe_set
Set if this is an observe receive PDU.
uint8_t last_type
Last request type (CON/NON)
coap_tick_t last_used
Last time data sent or 0.
uint8_t observe[3]
Observe data (if set) (only 24 bits)
uint16_t content_format
Content format for the set of blocks.
coap_str_const_t * uri_path
Structure to hold large body (many blocks) transmission information.
coap_release_large_data_t release_func
large data de-alloc function
uint8_t blk_size
large block transmission size
union coap_lg_xmit_t::@1 b
const uint8_t * data
large data ptr
int last_block
last acknowledged block number
size_t offset
large data next offset to transmit
coap_pdu_t pdu
skeletal PDU
size_t length
large data length
coap_tick_t last_used
Last time all data sent or 0.
uint16_t option
large block transmisson CoAP option
void * app_ptr
applicaton provided ptr for de-alloc function
Iterator to run through PDU options.
coap_option_num_t number
decoded option number
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
uint8_t * token
first byte of token, if any, or options
size_t body_length
Holds body data length.
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.
size_t body_offset
Holds body data offset.
coap_pdu_code_t code
request method (value 1–31) or response code (value 64-255)
uint8_t token_length
length of Token
uint8_t hdr_size
actual size used for protocol-specific header
uint8_t * data
first byte of payload, if any
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
size_t alloc_size
allocated storage for token, options and payload
size_t body_total
Holds body data total size.
coap_pdu_type_t type
message type
Structure to keep track of received blocks.
struct coap_lg_range range[COAP_RBLOCK_CNT]
Abstraction of resource that can be attached to coap_context_t.
coap_str_const_t * uri_path
Request URI Path for this resource.
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
coap_lg_xmit_t * lg_xmit
list of large transmissions
uint64_t tx_token
Next token number to use.
uint8_t block_mode
Zero or more COAP_BLOCK_ or'd options.
coap_lg_srcv_t * lg_srcv
Server list of expected large receives.
coap_lg_crcv_t * lg_crcv
Client list of expected large receives.
coap_context_t * context
session's context
CoAP string data definition.
size_t length
length of string