Commit b966ba16 authored by Pieter De Gendt's avatar Pieter De Gendt Committed by Anas Nashif
Browse files

net: coap: Fix size1 for block1 transfers



According to RFC-7959:
When uploading with coap block1 requests the server may respond
with a size1 option (together with the response code 4.13).
This to indicate the maximum size the server is able and willing
to handle.

This commit changes the total_size in the current block context
being handled to the optional size1 option value from the server.

Signed-off-by: default avatarPieter De Gendt <pieter.degendt@basalte.be>
parent 07b9e4e9
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -1019,7 +1019,10 @@ static int update_control_block1(struct coap_block_context *ctx,
	}

	ctx->block_size = GET_BLOCK_SIZE(block);

	if (size >= 0) {
		ctx->total_size = size;
	}

	return 0;
}
@@ -1057,16 +1060,13 @@ int coap_update_from_block(const struct coap_packet *cpkt,
	size1 = coap_get_option_int(cpkt, COAP_OPTION_SIZE1);
	size2 = coap_get_option_int(cpkt, COAP_OPTION_SIZE2);

	size1 = size1 == -ENOENT ? 0 : size1;
	size2 = size2 == -ENOENT ? 0 : size2;

	if (is_request(cpkt)) {
		r = update_control_block2(ctx, block2, size2);
		if (r) {
			return r;
		}

		return update_descriptive_block(ctx, block1, size1);
		return update_descriptive_block(ctx, block1, size1 == -ENOENT ? 0 : size1);
	}

	r = update_control_block1(ctx, block1, size1);
@@ -1074,7 +1074,7 @@ int coap_update_from_block(const struct coap_packet *cpkt,
		return r;
	}

	return update_descriptive_block(ctx, block2, size2);
	return update_descriptive_block(ctx, block2, size2 == -ENOENT ? 0 : size2);
}

size_t coap_next_block(const struct coap_packet *cpkt,