Fix IEEE 802.15.4 address handling and raw transmit error propagation (closes 596) - #597
Conversation
…e fake PHY’s successful transmit callback status from arbitrary 2137 to 0 so it doesn't always error out
jrvanwhy
left a comment
There was a problem hiding this comment.
Looks good from a libtock-rs perspective. I'll let someone from the Network WG (or at least whom is familiar with the 802.15.4 syscall driver) make sure the change makes sense W.R.T. that API.
If no-one else looks at it within a week, ping me and I'll merge this.
tyler-potyondy
left a comment
There was a problem hiding this comment.
Looks good to go! Thanks for fixing this @potto216!
Checked the api changes against libtock-c's (which has been much more heavily tested) and this matches.
| self.transmitted_frames.set(transmitted_frames); | ||
| self.share_ref | ||
| .schedule_upcall(subscribe::FRAME_TRANSMITTED, (2137, 0, 0)) | ||
| .schedule_upcall(subscribe::FRAME_TRANSMITTED, (0, 0, 0)) |
There was a problem hiding this comment.
Out of curiosity, @potto216 do you know why this was 2137?
There was a problem hiding this comment.
@tyler-potyondy Interesting question and I do not. I could not find another use of that value as an error or return code in libtock-rs, libtock-c, or tock. Also, I didn't see any reference to it in the commit with the change (cde91be). And the documentation on the subscribe didn't suggest anything (below)
Subscribe Number: 1
- Description: Callback when a frame transmission completes.
- Argument 1: Status code (success or error).
- Argument 2: acked flag (0/1) indicating whether the frame was acked.
- Argument 3: Unused.
- Returns: Ok(()).
I only ran into it when my tests failed after following Codex's advice in transmit_frame_raw to not just always return ok for after yielding
https://github.com/tock/libtock-rs/pull/597/changes#diff-9836a6938b05d997dc1c24e564ec5f7d167ab928a283344a0c9e96b7ca277340R195
There was a problem hiding this comment.
I'm going to hazard a guess that this is either a copy-paste error, or something from a now-outdated design.
Overview
This PR fixes three issues in the libtock-rs IEEE 802.15.4 API and closes #596. The issues fixed are:
set_address_short()andset_pan()incorrectly added 1 to values before passing them to the Tock driver.u16before subtracting the offset added by the driver.transmit_frame_raw()ignored errors reported through the transmission-complete upcall.This work follows the discussion Why do Tock's MAC and physical IEEE 802.15.4 capsule drivers add 1 to their
CommandReturn::success_u32return values?.Other IEEE 802.15.4 changes are outside the scope of this PR and will be addressed separately.
Address and PAN setters
The Tock IEEE 802.15.4 drivers expect short addresses and PAN IDs to be passed without modification:
SET_SHORT_ADDRpassesarg1 as u16directly toset_address().SET_PANpassesarg1 as u16directly toset_pan().However, libtock-rs previously added 1 before invoking these commands:
This shifted every configured value and caused
0xffffto wrap to zero when the driver narrowed it tou16.This PR removes the incorrect additions and passes both values to the driver as-is.
Address and PAN getters
Unlike the setter commands, the Tock drivers add 1 when returning a short address or PAN ID:
GET_SHORT_ADDRGET_PANlibtock-rs must therefore subtract 1 when decoding these responses. The subtraction must happen while the value is still a
u32:Casting before subtracting is incorrect for
0xffff. The driver encodes this value as0x1_0000, which requires 17 bits. Narrowing it first produces zero, after which subtracting 1 can overflow.Raw transmission errors
transmit_frame_raw()previously returnedOk(())whenever the transmission-complete upcall ran, regardless of the status reported by that upcall.This PR checks the callback status and:
Ok(())when the status is zero.ErrorCode.ErrorCode::Failif the status is not a recognized error code.Fake driver and tests
The fake IEEE 802.15.4 driver now matches the Tock drivers by adding 1 to values returned by
GET_SHORT_ADDRandGET_PAN.The configuration tests now exercise round trips for:
0x00000x00010xffffThese cases verify both the setter behavior and correct decoding of the getter responses.
One code discrepancy to fix before publishing: the current local diff changes
get_address_short()to subtract before narrowing, butget_pan()still contains:To match this description and handle
0xffff, it should be:AI Usage
I used OpenAI Codex to help with the fix and Google Gemni to review the patch. I reviewed all committed code.