From 21f16515b5d3f4d246d16e5ee0f840300514f246 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Mon, 24 Jun 2019 16:21:30 +0100 Subject: [PATCH] Add SIZE1 Option when sending BLOCK1 Option in packets As per https://tools.ietf.org/html/rfc7959#section-4 ... Implementation Notes: o As a quality of implementation consideration, block-wise transfers for which the total size considerably exceeds the size of one block are expected to include size indications, whenever those can be provided without undue effort (preferably with the first block exchanged) ... examples/client.c: Include SIZE1 Option when sending data using BLOCK1 Option. --- examples/client.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/client.c b/examples/client.c index d5b07a13..bba43e4d 100644 --- a/examples/client.c +++ b/examples/client.c @@ -168,8 +168,15 @@ coap_new_request(coap_context_t *ctx, if (length) { if ((flags & FLAGS_BLOCK) == 0) coap_add_data(pdu, length, data); - else + else { + unsigned char buf[4]; + coap_add_option(pdu, + COAP_OPTION_SIZE1, + coap_encode_var_safe(buf, sizeof(buf), length), + buf); + coap_add_block(pdu, length, data, block.num, block.szx); + } } return pdu; @@ -539,6 +546,11 @@ message_handler(struct coap_context_t *ctx, coap_encode_var_safe(buf, sizeof(buf), (block.num << 4) | (block.m << 3) | block.szx), buf); + coap_add_option(pdu, + COAP_OPTION_SIZE1, + coap_encode_var_safe(buf, sizeof(buf), payload.length), + buf); + coap_add_block(pdu, payload.length, payload.s,