Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: lwm2m: Add support for blockwise GET and FETCH #61858

Merged
merged 8 commits into from
Sep 27, 2023
14 changes: 14 additions & 0 deletions include/zephyr/net/coap.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,20 @@ int coap_get_option_int(const struct coap_packet *cpkt, uint16_t code);
*/
int coap_get_block1_option(const struct coap_packet *cpkt, bool *has_more, uint8_t *block_number);

/**
* @brief Get values from CoAP block2 option.
*
* Decode block number and block size from option. Ignore the has_more flag
* as it should always be zero on queries.
*
* @param cpkt Packet to be inspected
* @param block_number Is set to the number of the block
*
* @return Integer value of the block size in case of success
* or negative in case of error.
*/
int coap_get_block2_option(const struct coap_packet *cpkt, uint8_t *block_number);
SeppoTakalo marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Retrieves BLOCK{1,2} and SIZE{1,2} from @a cpkt and updates
* @a ctx accordingly.
Expand Down
13 changes: 13 additions & 0 deletions subsys/net/lib/coap/coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,19 @@ int coap_get_block1_option(const struct coap_packet *cpkt, bool *has_more, uint8
return ret;
}

int coap_get_block2_option(const struct coap_packet *cpkt, uint8_t *block_number)
{
int ret = coap_get_option_int(cpkt, COAP_OPTION_BLOCK2);

if (ret < 0) {
return ret;
}

*block_number = GET_NUM(ret);
ret = 1 << (GET_BLOCK_SIZE(ret) + 4);
return ret;
}

int insert_option(struct coap_packet *cpkt, uint16_t code, const uint8_t *value, uint16_t len)
{
uint16_t offset = cpkt->hdr_len;
Expand Down
1 change: 1 addition & 0 deletions subsys/net/lib/lwm2m/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ zephyr_library_sources(
lwm2m_obj_device.c
lwm2m_rw_link_format.c
lwm2m_rw_plain_text.c
lwm2m_rw_opaque.c
lwm2m_util.c
lwm2m_rd_client.c
)
Expand Down
2 changes: 2 additions & 0 deletions subsys/net/lib/lwm2m/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ config LWM2M_COAP_BLOCK_TRANSFER
help
LwM2M messages with a big body that exceed the block size will be split
into blocks for sending.
To append CoAP ETag option into outgoing block transfers, CONFIG_SYS_HASH_FUNC32 should
be enabled.

config LWM2M_CANCEL_OBSERVE_BY_PATH
bool "Use path matching as fallback for cancel-observe"
Expand Down
6 changes: 4 additions & 2 deletions subsys/net/lib/lwm2m/lwm2m_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ static int socket_recv_message(struct lwm2m_ctx *client_ctx)
}

in_buf[len] = 0U;
lwm2m_udp_receive(client_ctx, in_buf, len, &from_addr, handle_request);
lwm2m_udp_receive(client_ctx, in_buf, len, &from_addr);

return 0;
}
Expand Down Expand Up @@ -675,7 +675,9 @@ static int socket_send_message(struct lwm2m_ctx *client_ctx)
}

if (msg->type != COAP_TYPE_CON) {
lwm2m_reset_message(msg, true);
if (!lwm2m_outgoing_is_part_of_blockwise(msg)) {
lwm2m_reset_message(msg, true);
}
}

return rc;
Expand Down
Loading
Loading