Commit 2f35d11b authored by Marco Argiolas's avatar Marco Argiolas Committed by Fabio Baltieri
Browse files

net: lib: lwm2m: block 0 resets prev block transfer for same resource



As stated in "[RFC7959], Section 2.5":
   "The Block1 Option provides no way for a single endpoint to perform
   multiple concurrently proceeding block-wise request payload transfer
   (e.g., PUT or POST) operations to the same resource.  Starting a new
   block-wise sequence of requests to the same resource (before an old
   sequence from the same endpoint was finished) simply overwrites the
   context the server may still be keeping."

Signed-off-by: default avatarMarco Argiolas <marco.argiolas@ftpsolutions.com.au>
parent 215782aa
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -2055,11 +2055,15 @@ static int parse_write_op(struct lwm2m_message *msg, uint16_t format)

		block_num = GET_BLOCK_NUM(block_opt);

		/* Try to retrieve existing block context. If one not exists,
		 * and we've received first block, allocate new context.
		/*
		 * RFC7959: 2.5. Using the Block1 Option
		 * If we've received first block, replace old context (if any) with a new one.
		 */
		r = get_block_ctx(&msg->path, &block_ctx);
		if (r < 0 && block_num == 0) {
		if (block_num == 0) {
			/* free block context for previous incomplete transfer */
			free_block_ctx(block_ctx);

			r = init_block_ctx(&msg->path, &block_ctx);
		}