Skip to content

Commit 5f43388

Browse files
rlubosdleach02
authored andcommitted
net: coap: Parse more flag in coap_get_block2_option()
Parse the more flag in coap_get_block2_option(), so that the function can be used not only with requests but also with replies (where the more flag should not be ignored). Signed-off-by: Robert Lubos <[email protected]>
1 parent 3902a99 commit 5f43388

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

include/zephyr/net/coap.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -892,16 +892,17 @@ int coap_get_block1_option(const struct coap_packet *cpkt, bool *has_more, uint3
892892
/**
893893
* @brief Get values from CoAP block2 option.
894894
*
895-
* Decode block number and block size from option. Ignore the has_more flag
896-
* as it should always be zero on queries.
895+
* Decode block number, more flag and block size from option.
897896
*
898897
* @param cpkt Packet to be inspected
898+
* @param has_more Is set to the value of the more flag
899899
* @param block_number Is set to the number of the block
900900
*
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, uint32_t *block_number);
904+
int coap_get_block2_option(const struct coap_packet *cpkt, bool *has_more,
905+
uint32_t *block_number);
905906

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

subsys/net/lib/coap/coap.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,14 +1356,16 @@ int coap_get_block1_option(const struct coap_packet *cpkt, bool *has_more, uint3
13561356
return ret;
13571357
}
13581358

1359-
int coap_get_block2_option(const struct coap_packet *cpkt, uint32_t *block_number)
1359+
int coap_get_block2_option(const struct coap_packet *cpkt, bool *has_more,
1360+
uint32_t *block_number)
13601361
{
13611362
int ret = coap_get_option_int(cpkt, COAP_OPTION_BLOCK2);
13621363

13631364
if (ret < 0) {
13641365
return ret;
13651366
}
13661367

1368+
*has_more = GET_MORE(ret);
13671369
*block_number = GET_NUM(ret);
13681370
ret = 1 << (GET_BLOCK_SIZE(ret) + 4);
13691371
return ret;

subsys/net/lib/lwm2m/lwm2m_message_handling.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2650,10 +2650,11 @@ 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+
bool more;
26532654
uint32_t block;
26542655
enum coap_block_size block_size;
26552656

2656-
r = coap_get_block2_option(cpkt, &block);
2657+
r = coap_get_block2_option(cpkt, &more, &block);
26572658
if (r < 0) {
26582659
LOG_ERR("Failed to parse BLOCK2");
26592660
return;

0 commit comments

Comments
 (0)