Skip to content

Commit 3902a99

Browse files
rlubosdleach02
authored andcommitted
net: coap: Fix underlying type for block number
The block number in block1/2 options can be encoded on up to 20 bits according to RFC 7959, therefore the underlying type used in helper functions to retrieve the block number should be large enough to hold the result. Therefore, replace the container for block number with uint32_t instead of uint8_t. Signed-off-by: Robert Lubos <[email protected]>
1 parent 1fe1c96 commit 3902a99

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

include/zephyr/net/coap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ int coap_get_option_int(const struct coap_packet *cpkt, uint16_t code);
887887
* @return Integer value of the block size in case of success
888888
* or negative in case of error.
889889
*/
890-
int coap_get_block1_option(const struct coap_packet *cpkt, bool *has_more, uint8_t *block_number);
890+
int coap_get_block1_option(const struct coap_packet *cpkt, bool *has_more, uint32_t *block_number);
891891

892892
/**
893893
* @brief Get values from CoAP block2 option.
@@ -901,7 +901,7 @@ int coap_get_block1_option(const struct coap_packet *cpkt, bool *has_more, uint8
901901
* @return Integer value of the block size in case of success
902902
* or negative in case of error.
903903
*/
904-
int coap_get_block2_option(const struct coap_packet *cpkt, uint8_t *block_number);
904+
int coap_get_block2_option(const struct coap_packet *cpkt, uint32_t *block_number);
905905

906906
/**
907907
* @brief Retrieves BLOCK{1,2} and SIZE{1,2} from @a cpkt and updates

subsys/net/lib/coap/coap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ int coap_get_option_int(const struct coap_packet *cpkt, uint16_t code)
13421342
return val;
13431343
}
13441344

1345-
int coap_get_block1_option(const struct coap_packet *cpkt, bool *has_more, uint8_t *block_number)
1345+
int coap_get_block1_option(const struct coap_packet *cpkt, bool *has_more, uint32_t *block_number)
13461346
{
13471347
int ret = coap_get_option_int(cpkt, COAP_OPTION_BLOCK1);
13481348

@@ -1356,7 +1356,7 @@ int coap_get_block1_option(const struct coap_packet *cpkt, bool *has_more, uint8
13561356
return ret;
13571357
}
13581358

1359-
int coap_get_block2_option(const struct coap_packet *cpkt, uint8_t *block_number)
1359+
int coap_get_block2_option(const struct coap_packet *cpkt, uint32_t *block_number)
13601360
{
13611361
int ret = coap_get_option_int(cpkt, COAP_OPTION_BLOCK2);
13621362

subsys/net/lib/lwm2m/lwm2m_message_handling.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,7 +2650,7 @@ static void handle_ongoing_block2_tx(struct lwm2m_message *msg, struct coap_pack
26502650
{
26512651
#if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER)
26522652
int r;
2653-
uint8_t block;
2653+
uint32_t block;
26542654
enum coap_block_size block_size;
26552655

26562656
r = coap_get_block2_option(cpkt, &block);
@@ -2688,8 +2688,8 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_
26882688
int r;
26892689
#if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER)
26902690
bool more_blocks = false;
2691-
uint8_t block_num;
2692-
uint8_t last_block_num;
2691+
uint32_t block_num;
2692+
uint32_t last_block_num;
26932693
#endif
26942694
bool has_block2;
26952695

0 commit comments

Comments
 (0)