Skip to content

Commit 919c265

Browse files
committed
I2C transport: Fix check for Byte Count field and packet length
The complete packet includes destination address, command code, byte count and source address. The check previously accounted only for the source adddress, while the checked packet includes the whole header at that point. Signed-off-by: Marvin Gudel <marvin.gudel@9elements.com>
1 parent aac576f commit 919c265

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

mctp-estack/src/i2c.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ impl MctpI2cEncap {
106106

107107
let header =
108108
MctpI2cHeader::decode(packet.get(..4).ok_or(Error::InvalidInput)?)?;
109-
// +1 for i2c source address field
110-
if header.byte_count != packet.len() + 1 {
109+
// total packet len == byte_count + 3 (destination, command code, byte count)
110+
// pec is not included
111+
if header.byte_count + 3 != packet.len() {
112+
trace!("Packet byte count mismatch");
111113
return Err(Error::InvalidInput);
112114
}
113115

0 commit comments

Comments
 (0)