net: lwm2m: Fix how payload offset is calculated
Instead of manually computing payload offset, let the CoAP library do the work, and use the payload pointer returned by the `coap_packet_get_payload()` function instead. Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
parent
0bc4e7619b
commit
b369156e28
3 changed files with 11 additions and 5 deletions
|
@ -760,7 +760,7 @@ const uint8_t *coap_packet_get_payload(const struct coap_packet *cpkt, uint16_t
|
||||||
|
|
||||||
payload_len = cpkt->offset - cpkt->hdr_len - cpkt->opt_len;
|
payload_len = cpkt->offset - cpkt->hdr_len - cpkt->opt_len;
|
||||||
if (payload_len > 1) {
|
if (payload_len > 1) {
|
||||||
*len = payload_len - 1; /* substract payload marker length */
|
*len = payload_len - 1; /* subtract payload marker length */
|
||||||
} else {
|
} else {
|
||||||
*len = 0U;
|
*len = 0U;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3653,6 +3653,7 @@ static int handle_request(struct coap_packet *request,
|
||||||
uint16_t payload_len = 0U;
|
uint16_t payload_len = 0U;
|
||||||
bool last_block = false;
|
bool last_block = false;
|
||||||
bool ignore = false;
|
bool ignore = false;
|
||||||
|
const uint8_t *payload_start;
|
||||||
|
|
||||||
/* set CoAP request / message */
|
/* set CoAP request / message */
|
||||||
msg->in.in_cpkt = request;
|
msg->in.in_cpkt = request;
|
||||||
|
@ -3823,8 +3824,12 @@ static int handle_request(struct coap_packet *request,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* setup incoming data */
|
/* setup incoming data */
|
||||||
msg->in.offset = msg->in.in_cpkt->hdr_len + msg->in.in_cpkt->opt_len;
|
payload_start = coap_packet_get_payload(msg->in.in_cpkt, &payload_len);
|
||||||
coap_packet_get_payload(msg->in.in_cpkt, &payload_len);
|
if (payload_len > 0) {
|
||||||
|
msg->in.offset = payload_start - msg->in.in_cpkt->data;
|
||||||
|
} else {
|
||||||
|
msg->in.offset = msg->in.in_cpkt->offset;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check for block transfer */
|
/* Check for block transfer */
|
||||||
|
|
||||||
|
|
|
@ -211,6 +211,7 @@ do_firmware_transfer_reply_cb(const struct coap_packet *response,
|
||||||
size_t write_buflen;
|
size_t write_buflen;
|
||||||
uint8_t resp_code, *write_buf;
|
uint8_t resp_code, *write_buf;
|
||||||
struct coap_block_context received_block_ctx;
|
struct coap_block_context received_block_ctx;
|
||||||
|
const uint8_t *payload_start;
|
||||||
|
|
||||||
/* token is used to determine a valid ACK vs a separated response */
|
/* token is used to determine a valid ACK vs a separated response */
|
||||||
tkl = coap_header_get_token(check_response, token);
|
tkl = coap_header_get_token(check_response, token);
|
||||||
|
@ -266,9 +267,9 @@ do_firmware_transfer_reply_cb(const struct coap_packet *response,
|
||||||
last_block = !coap_next_block(check_response, &firmware_block_ctx);
|
last_block = !coap_next_block(check_response, &firmware_block_ctx);
|
||||||
|
|
||||||
/* Process incoming data */
|
/* Process incoming data */
|
||||||
payload_offset = response->hdr_len + response->opt_len;
|
payload_start = coap_packet_get_payload(response, &payload_len);
|
||||||
coap_packet_get_payload(response, &payload_len);
|
|
||||||
if (payload_len > 0) {
|
if (payload_len > 0) {
|
||||||
|
payload_offset = payload_start - response->data;
|
||||||
LOG_DBG("total: %zd, current: %zd",
|
LOG_DBG("total: %zd, current: %zd",
|
||||||
firmware_block_ctx.total_size,
|
firmware_block_ctx.total_size,
|
||||||
firmware_block_ctx.current);
|
firmware_block_ctx.current);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue