-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
coap_packet_get_payload() returns the wrong size #36739
Comments
@rlubos could you have a look at this? |
Sure, I'll analyze the issue and come back to you. |
The coap specs says:
|
I think you're right, there seems to be some divergence in how particular I think we should unify how particular fields are handled in both cases, when a packet is created by the application, and when it's parsed from the received data. I think your proposal might be a good direction, however, it won't work in the latter case now, as parsing the packet does not set the I'll try to propose some cleanup in the near future, so that |
That is true actually, I had not noticed. I think that after the packet is parsed in
I will try to fix it here locally and once it works, I will try to submit a PR. |
Why do you think we need +1 though? I think the We'll also need more changes than merely setting the offset value, for the aforementioned payload marker, which is handled in a different way on TX/RX path. I think it should not be counted into I'd like to extend the current unit tests to cover this functionality better so we don't make changes blindly, I'll try to propose something today/tomorrow. |
@rlubos I agree the +1 is not required. I am currently trying to fix it, I will let you know what my findings are. Thanks |
@efra-mx-aqua Please try this one: https://github.com/rlubos/zephyr/tree/coap/fix-get-payload I think this is the complete fix, I wanted to add some extra tests though before submitting a PR |
I have something similar at the moment. I am just trying to do a proper fix for the coap module. Actually, I also found that |
That's likely the Payload Marker which's incorrectly counted in the |
The function
coap_packet_get_payload()
returns the wrong size, it returns the number of bytes left for payload, no the actual payload size.the current calculation is:
Which means that
payload_len
includes the unused bytes.Snippet create packet:
Evaluating with the snippet from above:
The offset is moving with every append, therefore this actual pyload length can be calculated as follows:
This is what I get on my log:
This is what I would expect:
Environment:
The text was updated successfully, but these errors were encountered: