Skip to content

Commit

Permalink
coap: zephyr: 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.

The Kconfig value was previously masked by a bitwise operation. This should
not be necessary as that symbol was updated to a 'choice' in Kconfig so we
can be confident that the value is valid coap size or it would have
triggered a static assert.

Signed-off-by: Mike Szczys <mike@golioth.io>
  • Loading branch information
szczys committed Sep 3, 2024
1 parent 6453e95 commit b8f8694
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/coap_client_zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "golioth_util.h"
#include "mbox.h"

#include "coap_blockwise.h"
#include "coap_client_zephyr.h"
#include "pathv.h"
#include "zephyr_coap_req.h"
Expand Down Expand Up @@ -131,7 +132,10 @@ static int golioth_coap_req_append_block1_option(golioth_coap_request_msg_t *req
*/
req->request_wo_block1 = req->request;
}
val |= BLOCKSIZE_TO_SZX(CONFIG_GOLIOTH_BLOCKWISE_UPLOAD_MAX_BLOCK_SIZE) & 0x07;

struct post_block_ctx *pb_ctx = req_msg->post_block.arg;

val |= pb_ctx->negotiated_blocksize;
val |= req_msg->post_block.is_last ? 0x00 : 0x08;
val |= req_msg->post_block.block_index << 4;
return coap_append_option_int(&req->request, COAP_OPTION_BLOCK1, val);
Expand Down

0 comments on commit b8f8694

Please sign in to comment.