Skip to content

Commit

Permalink
coap: libcoap: use negotiated block size when adding block1
Browse files Browse the repository at this point in the history
Use the negotiated block size when initializing the block1 option of the
coap packet.

This moves the use of the compiled-in
CONFIG_GOLIOTH_BLOCKWISE_UPLOAD_MAX_BLOCK_SIZE value to the initialization
step of the negotiated value, and allows for the negotiated value to be
updated based on the server preference, then used for all subsequent coap
requests in the block upload process.

Signed-off-by: Mike Szczys <[email protected]>
  • Loading branch information
szczys committed Oct 8, 2024
1 parent e18b6fb commit 909ff52
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/coap_client_libcoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,14 @@ static void golioth_coap_add_accept(coap_pdu_t *request, enum golioth_content_ty

static void golioth_coap_add_block1(coap_pdu_t *request,
size_t block_index,
size_t block_size,
size_t block_szx,
bool is_last)
{
size_t szx = BLOCKSIZE_TO_SZX(block_size);
assert(szx != -1);
assert(block_szx <= COAP_MAX_BLOCK_SZX);
coap_block_t block = {
.num = block_index,
.m = !is_last,
.szx = szx,
.szx = block_szx,
};

unsigned char buf[4];
Expand Down Expand Up @@ -571,7 +570,7 @@ static void golioth_coap_post_block(golioth_coap_request_msg_t *req,
golioth_coap_add_content_type(req_pdu, req->post_block.content_type);
golioth_coap_add_block1(req_pdu,
req->post_block.block_index,
CONFIG_GOLIOTH_BLOCKWISE_UPLOAD_MAX_BLOCK_SIZE,
req->post_block.block_szx,
req->post_block.is_last);
coap_add_data(req_pdu, req->post_block.payload_size, (unsigned char *) req->post_block.payload);
coap_send(session, req_pdu);
Expand Down

0 comments on commit 909ff52

Please sign in to comment.