Skip to content

Commit a6560c1

Browse files
rluboscfriedt
authored andcommitted
net: coap_client: Handle block size negotiation on upload
During block uploads, the server may respond with Block 1 option with a smaller block size than currently used (so called block size negotiation). The CoAP client however did not read the Block 1 option from the response, therefore ignoring the server request to lower the block size. Signed-off-by: Robert Lubos <[email protected]>
1 parent 74d715c commit a6560c1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

subsys/net/lib/coap/coap_client.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,13 +935,24 @@ static int handle_response(struct coap_client *client, const struct coap_packet
935935

936936
/* Check if this was a response to last blockwise send */
937937
if (internal_req->send_blk_ctx.total_size > 0) {
938+
int block1_option;
939+
938940
blockwise_transfer = true;
939941
internal_req->offset = internal_req->send_blk_ctx.current;
940942
if (internal_req->send_blk_ctx.total_size == internal_req->send_blk_ctx.current) {
941943
last_block = true;
942944
} else {
943945
last_block = false;
944946
}
947+
948+
block1_option = coap_get_option_int(response, COAP_OPTION_BLOCK1);
949+
if (block1_option > 0) {
950+
int block_size = GET_BLOCK_SIZE(block1_option);
951+
952+
if (block_size < internal_req->send_blk_ctx.block_size) {
953+
internal_req->send_blk_ctx.block_size = block_size;
954+
}
955+
}
945956
}
946957

947958
/* Until the last block of a transfer, limit data size sent to the application to the block

0 commit comments

Comments
 (0)