Issue with User-Defined Payload Transmission Over SMP: Payload Length Calculation and Memory Address Handling #85521
Labels
area: mcumgr
bug
The issue is a bug, or the PR is fixing a bug
priority: low
Low impact/importance bug
Describe the bug
I am attempting to send a user-defined payload as a response over
SMP
by enabling theCONFIG_MCUMGR_MGMT_CUSTOM_PAYLOAD
flag and settingcustom_payload
to true in the handler'smgmt_group
struct.In the implementation, I am writing directly into the network buffer net_buf using Zephyr's net_buf library functions. However, when attempting to send the response, no data is being transmitted to the client, and the payload length is incorrectly set to 0 in the smp_hdr.
Upon further investigation, I discovered that the payload length in smp_hdr is being calculated as the difference between the payload_mut and net_buf memory addresses. This suggests that, for a correct calculation, one of the addresses has to change during the writing process, which is what occurs in fact in the case of using CBOR encoding functions such as zcbor_tstr_put_lit where the writer->zs->payload_mut address is moved to the tail of the memory buffer. However, when writing data to net_buf using the Zephyr API, neither of the memory addresses changes, leading to the payload length issue. As a temporary solution, I manually updated the payload_mut address to point to the tail of the allocated memory by adjusting it with
payload_mut = payload_mut + bytes_written
To Reproduce
Enable the CONFIG_MCUMGR_MGMT_CUSTOM_PAYLOAD flag.
Set custom_payload to true in the handler's mgmt_group struct.
Write custom data into the net_buf using net_buf library functions.
Attempt to send the SMP response.
Observe that no data is transmitted, and the payload length in the smp_hdr is set to 0.
Expected behavior
The custom payload should be correctly written into the network buffer and transmitted as part of the SMP response. The payload length in smp_hdr should reflect the actual data written.
Actual Behavior
No data is transmitted to the client, and the payload length in smp_hdr is 0.
Impact
Logs and console output
Environment (please complete the following information):
Additional context/Suggested Enhancement
The text was updated successfully, but these errors were encountered: