Skip to content

Commit f021236

Browse files
marco85mars20aescolar
authored andcommitted
net: lib: lwm2m: fix formula for expected next block
Block size is a 3-bit value mapping values [0, 6] to powers of 2 in the range [16, 1024]. Value 7 is invalid. The previous formula was not working in case the client's preferred size was 4 (or more) times bigger than the server's. This commit takes into account also the case the client's preferred size is smaller than the server's. Signed-off-by: Marco Argiolas <[email protected]>
1 parent 43de309 commit f021236

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

subsys/net/lib/lwm2m/lwm2m_message_handling.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,12 +2100,12 @@ static int parse_write_op(struct lwm2m_message *msg, uint16_t format)
21002100

21012101
block_ctx->last_block = last_block;
21022102

2103-
/* Initial block sent by the server might be larger than
2104-
* our block size therefore it is needed to take this
2105-
* into account when calculating next expected block
2106-
* number.
2103+
/* Initial block sent by the server might be larger or smaller than
2104+
* our block size, therefore it is needed to take this into account
2105+
* when calculating next expected block number.
21072106
*/
2108-
block_ctx->expected += GET_BLOCK_SIZE(block_opt) - block_ctx->ctx.block_size + 1;
2107+
block_ctx->expected +=
2108+
1 << MAX(0, GET_BLOCK_SIZE(block_opt) - block_ctx->ctx.block_size);
21092109
}
21102110

21112111
r = do_write_op(msg, format);

0 commit comments

Comments
 (0)