Skip to content

Add expected_response_size to GetReport command#888

Open
daniellehadar wants to merge 6 commits into
OpenDevicePartnership:mainfrom
razbhe10:personal/dhadar/use_buffer_size_get_report
Open

Add expected_response_size to GetReport command#888
daniellehadar wants to merge 6 commits into
OpenDevicePartnership:mainfrom
razbhe10:personal/dhadar/use_buffer_size_get_report

Conversation

@daniellehadar

Copy link
Copy Markdown

Add an optional buffer size parameter to GetReport so the I2C device layer can limit the read length to the actual expected payload size instead of always reading the full buffer. This avoids over-reading response in write_read transactions.

Add an optional buffer size parameter to GetReport so the I2C device
layer can limit the read length to the actual expected payload size
instead of always reading the full buffer. This avoids over-reading
on devices that are sensitive to read length in write_read transactions.
RobertZ2011
RobertZ2011 previously approved these changes Jun 11, 2026
Comment thread hid-service/src/i2c/device.rs Outdated
Comment thread hid-service/src/i2c/device.rs Outdated
Comment thread embedded-service/src/hid/command.rs Outdated
Comment thread embedded-service/src/hid/command.rs
@daniellehadar daniellehadar requested a review from jerrysxie June 16, 2026 06:34

@jerrysxie jerrysxie left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, pending fix for one failed CI on formatting.

}
}

Ok(Some(Response::FeatureReport(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the actual_frame_len is smaller than the response_size, I think we should return the actual_frame_len

if actual_frame_len > response_size { return Err(/* InvalidSize */); }
let returned_len = if constrained { actual_frame_len } else { response_size };
Ok(Some(Response::FeatureReport(
    self.buffer.reference().slice(0..returned_len).map_err(Error::Buffer)?,
)))

[0x05, 0x00, 0x1f, 0x02, EXTENDED_REPORT_ID, 0x06, 0x00]
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add the relevant tests?
(a) constrained read pulls exactly payload + 2 bytes and returns a slice of that length;
(b) device declaring a longer frame (actual_frame_len > response_size) → Err(InvalidSize);
(c) expected_payload_size exceeding the buffer → Err(InvalidSize) from get_mut.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be a bit tough to enable unit test in this module without some refactoring due to the static lifetime and we will need mocks for the i2c bus. Since @williampMSFT is refactoring this module right now, it is probably out of the scope for this PR.

@RobertZ2011 RobertZ2011 removed their assignment Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BREAKING CHANGE Marks breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants