Skip to content

Commit 982d4c2

Browse files
committed
pldm-file: host: calculate correct CRC for retries
Previously the CRC would have duplicate updates for XFER_CURRENT_PART requests (a retry), rather than only once for each part. Signed-off-by: Matt Johnston <[email protected]>
1 parent 389cd3e commit 982d4c2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

pldm-file/src/host.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ struct FileTransferContext {
3636
// Current transfer 0..len
3737
offset: usize,
3838
digest: crc::Digest<'static, u32, crc::Table<16>>,
39+
// Digest after adding the current part. Is copied to
40+
// `digest` after the next part is requested (to allow for retries).
41+
next_digest: crc::Digest<'static, u32, crc::Table<16>>,
3942
}
4043

4144
impl FileTransferContext {
@@ -45,6 +48,7 @@ impl FileTransferContext {
4548
len,
4649
offset: 0,
4750
digest: CRC32.digest(),
51+
next_digest: CRC32.digest(),
4852
}
4953
}
5054

@@ -384,7 +388,11 @@ impl<const N: usize> Responder<N> {
384388
let offset = match cmd.xfer_op {
385389
pldm::control::xfer_op::FIRST_PART
386390
| pldm::control::xfer_op::CURRENT_PART => xfer_ctx.offset,
387-
pldm::control::xfer_op::NEXT_PART => xfer_ctx.offset + part_size,
391+
pldm::control::xfer_op::NEXT_PART => {
392+
// have moved to the next part, can include the previous part's digest
393+
xfer_ctx.digest = xfer_ctx.next_digest.clone();
394+
xfer_ctx.offset + part_size
395+
}
388396
_ => Err(CCode::ERROR_INVALID_DATA)?,
389397
};
390398

@@ -427,8 +435,9 @@ impl<const N: usize> Responder<N> {
427435
host.read(data, xfer_ctx.start + offset)
428436
.map_err(|_| CCode::ERROR)?;
429437

430-
xfer_ctx.digest.update(data);
431-
let cs = xfer_ctx.digest.clone().finalize();
438+
xfer_ctx.next_digest = xfer_ctx.digest.clone();
439+
xfer_ctx.next_digest.update(data);
440+
let cs = xfer_ctx.next_digest.clone().finalize();
432441
resp_data.extend_from_slice(&cs.to_le_bytes());
433442

434443
xfer_ctx.offset = offset;

0 commit comments

Comments
 (0)