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.
This commit is contained in:
Jon Shallow committed 2019-06-24 16:21:30 +01:00
1 parent a5ffdf323d
commit 21f16515b5
1 file changed
+13 -1
+13 -1
View File
@@ -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,