12 #define min(a,b) ((a) < (b) ? (a) : (b))
65 size_t start, want, avail;
70 start = block->
num << (block->
szx + 4);
71 if (block->
num != 0 && data_length <= start) {
78 want = (size_t)1 << (block->
szx + 4);
82 block->
m = want < data_length - start;
89 if (data_length - start <= avail) {
100 "not enough space, even the smallest block does not fit\n");
103 newBlockSize =
coap_flsll((
long long)avail) - 5;
105 "decrease block size for %zu to %d\n", avail, newBlockSize);
107 block->
szx = newBlockSize;
109 block->
num <<= szx - block->
szx;
125 unsigned int block_num,
unsigned char block_szx) {
127 start = block_num << (block_szx + 4);
133 min(len - start, ((
size_t)1 << (block_szx + 4))),
152 unsigned char buf[4];
154 int block2_requested = 0;
164 block2_requested = 1;
165 if (block2.
num != 0 && length <= (block2.
num << (block2.
szx + 4))) {
168 length >> (block2.
szx + 4));
174 else if (subscription && subscription->
has_block2) {
175 block2 = subscription->
block;
177 block2_requested = 1;
182 memset(etag, 0,
sizeof(etag));
186 if ((block2.
num == 0) && subscription) {
204 if (block2_requested) {
264 uint8_t block_mode) {
278 const uint8_t *b,
size_t blen) {
281 return alen == blen && memcmp(a, b, blen) == 0;
283 return alen == blen && memcmp(a+bias, b+bias, 4) == 0;
288 const uint8_t *b,
size_t blen) {
289 return alen == blen && (alen == 0 || memcmp(a, b, alen) == 0);
351 int have_block_defined = 0;
359 "** %s: coap_send_large: COAP_BLOCK_USE_LIBCOAP not enabled\n",
365 #define MAX_BLK_LEN (((1 << 20) - 1) * (1 << (6 + 4)))
369 "Size of large buffer restricted to 0x%x bytes\n",
MAX_BLK_LEN);
416 blk_size =
coap_flsll((
long long)avail) - 4 - 1;
420 if (block.
szx < blk_size)
421 blk_size = block.
szx;
422 have_block_defined = 1;
425 if (avail < 16 && ((ssize_t)length > avail || have_block_defined)) {
428 "not enough space, even the smallest block does not fit\n");
432 chunk = (size_t)1 << (blk_size + 4);
433 if (have_block_defined && block.
num != 0) {
443 if (length >= block.
num * chunk) {
445 if (chunk > length - block.
num * chunk)
446 rem = length - block.
num * chunk;
451 release_func(session, app_ptr);
453 else if ((have_block_defined && length > chunk) || (ssize_t)length > avail) {
472 lg_xmit->blk_size = blk_size;
473 lg_xmit->option = option;
474 lg_xmit->data = data;
475 lg_xmit->length = length;
477 lg_xmit->release_func = release_func;
478 lg_xmit->last_payload = 0;
479 lg_xmit->last_used = 0;
480 lg_xmit->app_ptr = app_ptr;
484 if (!lg_xmit->b.b1.app_token)
490 lg_xmit->b.b1.count = 1;
491 token = ((++session->
tx_token) & 0xffffffff) +
492 ((uint64_t)lg_xmit->b.b1.count << 32);
493 memset(lg_xmit->b.b1.token, 0,
sizeof(lg_xmit->b.b1.token));
495 sizeof(token), token);
503 (
unsigned int)length),
511 lg_xmit->b.b2.resource = resource;
514 if (lg_xmit->b.b2.query) {
515 memcpy(lg_xmit->b.b2.query->s, query->
s, query->
length);
519 lg_xmit->b.b2.query = NULL;
521 lg_xmit->b.b2.etag = etag;
529 lg_xmit->b.b2.maxage_expire = 0;
534 (
unsigned int)length),
548 block.
m = ((block.
num + 1) * chunk) < lg_xmit->length;
552 (block.
num << 4) | (block.
m << 3) | lg_xmit->blk_size),
556 memcpy(&lg_xmit->pdu, pdu,
sizeof(lg_xmit->pdu));
558 8 + lg_xmit->pdu.used_size + lg_xmit->pdu.hdr_size);
559 if (!lg_xmit->pdu.token)
562 lg_xmit->pdu.alloc_size = 8 + lg_xmit->pdu.used_size +
563 lg_xmit->pdu.hdr_size;
564 lg_xmit->pdu.token += lg_xmit->pdu.hdr_size;
565 memcpy(lg_xmit->pdu.token, pdu->
token, lg_xmit->pdu.used_size);
567 lg_xmit->pdu.data = lg_xmit->pdu.token + (pdu->
data - pdu->
token);
573 if (avail < (ssize_t)chunk) {
577 "not enough space, even the smallest block does not fit\n");
580 blk_size =
coap_flsll((
long long)avail) - 4 - 1;
581 block.
num = block.
num << (lg_xmit->blk_size - blk_size);
582 lg_xmit->blk_size = blk_size;
583 chunk = (size_t)1 << (lg_xmit->blk_size + 4);
587 (block.
num << 4) | (block.
m << 3) | lg_xmit->blk_size),
592 if (chunk > lg_xmit->length - block.
num * chunk)
593 rem = lg_xmit->length - block.
num * chunk;
597 lg_xmit->last_block = -1;
604 if (have_block_defined) {
608 (0 << 4) | (0 << 3) | blk_size), buf);
615 release_func(session, app_ptr);
624 release_func(session, app_ptr);
636 0, length, data, release_func, app_ptr);
654 unsigned char buf[4];
656 int block_requested = 0;
668 if (block.
num != 0 && length <= (block.
num << (block.
szx + 4))) {
671 length >> (block.
szx + 4));
677 else if (subscription && subscription->
has_block2) {
678 block = subscription->
block;
684 if ((block.
num == 0) && subscription) {
702 if (block_requested) {
723 maxage, etag, length, data,
724 release_func, app_ptr)) {
736 etag, length, data, release_func,
767 if (tim_rem > p->
last_used + partial_timeout - now)
768 tim_rem = p->
last_used + partial_timeout - now;
778 for (i = 0; i < rec_blocks->
used; i++) {
779 if (block_num < rec_blocks->range[i].begin)
781 if (block_num <= rec_blocks->range[i].end)
792 for (i = 0; i < rec_blocks->
used; i++) {
793 if (block < rec_blocks->range[i].begin)
795 if (block < rec_blocks->range[i].end)
799 if (block + 1 < total_blocks)
820 if (tim_rem > p->
last_used + partial_timeout - now)
821 tim_rem = p->
last_used + partial_timeout - now;
841 memcpy(&lg_crcv->
pdu, pdu,
sizeof(lg_crcv->
pdu));
858 memset(lg_crcv->
token, 0,
sizeof(lg_crcv->
token));
931 uint32_t *count, uint32_t max_count) {
934 for (i = 0; i < *count && *count < max_count; i++) {
935 if (num == out_blocks[i])
937 else if (num < out_blocks[i]) {
939 memmove(&out_blocks[i], &out_blocks[i+1], *count - i -1);
945 if (*count < max_count) {
976 uint16_t block_opt = 0;
977 uint32_t out_blocks[1];
978 const char *error_phrase;
988 uint32_t request_cnt, i;
1016 chunk = (size_t)1 << (p->
blk_size + 4);
1019 "found Block option, block size is %zu, block nr. %u, M %d\n",
1020 (
size_t)1 << (block.
szx + 4), block.
num, block.
m);
1022 if ((p->
offset + chunk) % ((
size_t)1 << (block.
szx + 4)) == 0) {
1027 block.
num = (uint32_t)(((p->
offset + chunk) >> (block.
szx + 4)) - 1);
1029 chunk = (size_t)1 << (p->
blk_size + 4);
1032 "new Block size is %u, block number %u completed\n",
1033 1 << (block.
szx + 4), block.
num);
1036 "ignoring request to increase Block size, "
1037 "next block is not aligned on requested block size "
1038 "boundary. (%zu x %u mod %u = %zu (which is not 0)\n",
1040 (1 << (block.
szx + 4)),
1041 (p->
offset + chunk) % ((
size_t)1 << (block.
szx + 4)));
1057 sizeof(
"Changing blocksize during request invalid")-1,
1058 (
const uint8_t *)
"Changing blocksize during request invalid");
1065 if (request_cnt == 0) {
1073 for (i = 0; i < request_cnt; i++) {
1076 block.
num = out_blocks[i];
1079 if (i + 1 < request_cnt) {
1087 pdu->
token, &drop_options);
1106 goto internal_issue;
1117 ((p->
offset + chunk < p->length) << 3) |
1120 goto internal_issue;
1141 goto internal_issue;
1150 goto internal_issue;
1152 if (i + 1 < request_cnt) {
1156 goto skip_app_handler;
1161 goto skip_app_handler;
1172 (
const uint8_t *)error_phrase);
1181 rec_blocks->
retry = 0;
1183 for (i = 0; i < rec_blocks->
used; i++) {
1184 if (block_num >= rec_blocks->
range[i].
begin &&
1185 block_num <= rec_blocks->range[i].end)
1188 if (block_num < rec_blocks->range[i].begin) {
1189 if (block_num + 1 == rec_blocks->
range[i].
begin) {
1197 memmove(&rec_blocks->
range[i+1], &rec_blocks->
range[i],
1198 (rec_blocks->
used - i) * sizeof (rec_blocks->
range[0]));
1204 if (block_num == rec_blocks->
range[i].
end + 1) {
1205 rec_blocks->
range[i].
end = block_num;
1206 if (i + 1 < rec_blocks->
used) {
1207 if (rec_blocks->
range[i+1].
begin == block_num + 1) {
1210 if (i+2 < rec_blocks->
used) {
1211 memmove (&rec_blocks->
range[i+1], &rec_blocks->
range[i+2],
1212 (rec_blocks->
used - (i+2)) * sizeof (rec_blocks->
range[0]));
1220 if (i == rec_blocks->
used) {
1252 const uint8_t *data = NULL;
1257 uint16_t block_option = 0;
1280 offset = block.
num << (block.
szx + 4);
1291 if (!p && block.
num != 0) {
1296 pdu->
body_total = length + offset + (block.
m ? 1 : 0);
1299 else if (!p && !(offset == 0 && block.
m == 0)) {
1303 (
const uint8_t *)
"Memory issue");
1305 goto skip_app_handler;
1310 p->resource = resource;
1314 p->content_format = fmt;
1315 p->total_len = total;
1316 p->amount_so_far = length;
1318 p->block_option = block_option;
1324 p->body_data = NULL;
1329 coap_add_data(response,
sizeof(
"Content-Format mismatch")-1,
1330 (
const uint8_t *)
"Content-Format mismatch");
1339 size_t chunk = (size_t)1 << (block.
szx + 4);
1344 coap_add_data(response,
sizeof(
"Too many missing blocks")-1,
1345 (
const uint8_t *)
"Too many missing blocks");
1353 goto call_app_handler;
1357 (uint32_t)(p->
total_len + chunk -1)/chunk)) {
1370 goto skip_app_handler;
1372 goto skip_app_handler;
1392 h(context, resource, session, pdu, token, query, response);
1397 goto skip_app_handler;
1406 if (total > offset + length + block.
m)
1417 h(context, resource, session, pdu, token, query, response);
1425 goto skip_app_handler;
1436 goto call_app_handler;
1441 goto skip_app_handler;
1476 size_t chunk = (size_t)1 << (p->
blk_size + 4);
1482 "found Block option, block size is %u, block nr. %u\n",
1483 1 << (block.
szx + 4), block.
num);
1485 if ((p->
offset + chunk) % ((
size_t)1 << (block.
szx + 4)) == 0) {
1490 block.
num = (uint32_t)(((p->
offset + chunk) >> (block.
szx + 4)) - 1);
1492 chunk = (size_t)1 << (p->
blk_size + 4);
1495 "new Block size is %u, block number %u completed\n",
1496 1 << (block.
szx + 4), block.
num);
1499 "next block is not aligned on requested block size boundary. "
1500 "(%zu x %u mod %u = %zu != 0)\n",
1502 (1 << (block.
szx + 4)),
1503 (p->
offset + chunk) % ((
size_t)1 << (block.
szx + 4)));
1528 size_t ltoken_length;
1530 token = (token & 0xffffffff) + ((uint64_t)(++p->
b.
b1.
count) << 32);
1540 ((p->
offset + chunk < p->length) << 3) |
1579 const uint8_t *data,
size_t offset,
size_t total)
1583 if (body_data == NULL && total) {
1586 if (body_data == NULL)
1590 if (offset + length <= total && body_data->length >= total) {
1591 memcpy(&body_data->
s[offset], data, length);
1608 memcpy(&body_data->
s[offset], data, length);
1636 int app_has_response = 0;
1639 uint16_t block_opt = 0;
1660 size_t size2 = size_opt ?
1675 uint16_t fmt = fmt_opt ?
1683 chunk = (size_t)1 << (block.
szx + 4);
1684 offset = block.
num * chunk;
1685 if (size2 < (offset + length)) {
1687 size2 = offset + length + 1;
1689 size2 = offset + length;
1721 "Data body updated during receipt - new request started\n");
1739 (0 << 4) | (0 << 3) | block.
szx),
1745 goto skip_app_handler;
1761 "found Block option, block size is %u, block nr. %u\n",
1762 1 << (block.
szx + 4), block.
num);
1763 if (block.
num == 0) {
1793 (size2 + chunk -1) / chunk)) {
1815 ((block.
num + 1) << 4) |
1816 (block.
m << 3) | block.
szx),
1823 goto skip_app_handler;
1829 goto call_app_handler;
1858 app_has_response = 1;
1868 goto skip_app_handler;
1878 if(size2 > block.
num*chunk + length + block.
m)
1896 app_has_response = 1;
1928 "libcoap unless coap_send_large() is used to transmit "
1936 if (block.
num != 0) {
1940 size_t chunk = (size_t)1 << (block.
szx + 4);
1959 return app_has_response;
1975 if (response->
code == 0)
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.
void coap_session_new_token(coap_session_t *session, size_t *len, uint8_t *data)
Creates a new token for use.
int coap_flsll(long long i)
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_binary_t *token, coap_string_t *query, coap_method_handler_t h, int *added_block)
coap_tick_t coap_block_check_lg_srcv_timeouts(coap_session_t *session, coap_tick_t now)
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.
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()...
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)
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)
int coap_write_block_opt(coap_block_t *block, uint16_t type, coap_pdu_t *pdu, size_t data_length)
Writes a block option of type type to message pdu.
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.
#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_get_block(coap_pdu_t *pdu, uint16_t type, coap_block_t *block)
Initializes block from pdu.
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.
int coap_add_data_large_response(coap_resource_t *resource, coap_session_t *session, coap_pdu_t *request, coap_pdu_t *response, const coap_binary_t *token, 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.
void coap_add_data_blocked_response(coap_resource_t *resource, coap_session_t *session, coap_pdu_t *request, coap_pdu_t *response, const coap_binary_t *token, 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.
void(* coap_release_large_data_t)(struct 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...
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_cancel_observe(coap_session_t *session, coap_binary_t *token, uint8_t type)
Cancel an observe that is being tracked by the client large receive logic when using coap_send_large(...
#define COAP_OPT_BLOCK_LAST(opt)
Returns the value of the least significant byte of a Block option opt.
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_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_context_t *, coap_resource_t *, coap_session_t *, coap_pdu_t *, coap_binary_t *, coap_string_t *, coap_pdu_t *)
Definition of message handler function.
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...
int coap_option_filter_set(coap_opt_filter_t *filter, uint16_t type)
Sets the corresponding entry for type in filter.
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.
#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_t * coap_check_option(coap_pdu_t *pdu, uint16_t type, coap_opt_iterator_t *oi)
Retrieves the first option of type type from pdu.
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.
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.
coap_subscription_t * coap_find_observer(coap_resource_t *resource, coap_session_t *session, const coap_binary_t *token)
Returns a subscription object for given peer.
#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().
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.
coap_mid_t coap_send(coap_session_t *session, coap_pdu_t *pdu)
Sends a CoAP message to given peer.
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
int coap_update_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Updates token in pdu with length len and data.
int coap_get_data(const coap_pdu_t *pdu, size_t *len, uint8_t **data)
Retrieves the length and data pointer of specified PDU.
size_t coap_add_option(coap_pdu_t *pdu, uint16_t type, size_t len, const uint8_t *data)
Adds option of given type to pdu that is passed as first parameter.
coap_pdu_t * coap_pdu_duplicate(const coap_pdu_t *old_pdu, coap_session_t *session, size_t token_length, uint8_t *token, coap_opt_filter_t *drop_options)
Duplicate an existing 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.
const char * coap_response_phrase(unsigned char code)
Returns a human-readable response phrase for the specified CoAP response code.
size_t coap_update_option(coap_pdu_t *pdu, uint16_t type, size_t len, const uint8_t *data)
Updates existing first option of given type in the pdu with the new data.
size_t coap_insert_option(coap_pdu_t *pdu, uint16_t type, size_t len, const uint8_t *data)
Inserts option of given type in the pdu with the appropriate data.
int coap_remove_option(coap_pdu_t *pdu, uint16_t type)
Removes option of given type from the pdu.
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.
#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
#define COAP_MEDIATYPE_TEXT_PLAIN
#define COAP_OPTION_CONTENT_TYPE
#define COAP_INVALID_MID
Indicates an invalid message id.
#define COAP_OPTION_MAXAGE
#define COAP_OPTION_OBSERVE
#define COAP_PDU_IS_REQUEST(pdu)
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.
uint16_t type
decoded option type
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.
uint8_t code
request method (value 1–31) or response code (value 64-255)
uint16_t mid
message id, if any, in regular host byte order
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
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.
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.
unsigned int observe
The next value for the Observe option.
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.
struct coap_context_t * context
session's context
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 string data definition.
size_t length
length of string
coap_block_t block
GET/FETCH request Block definition.
unsigned int has_block2
GET request had Block2 definition.
#define LL_DELETE(head, del)
#define LL_FOREACH(head, el)
#define LL_PREPEND(head, add)
#define LL_FOREACH_SAFE(head, el, tmp)