From 570d7a0b17de4239898d046da6cf93e579386562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mo=C5=84?= Date: Fri, 9 Feb 2024 20:48:41 +0100 Subject: [PATCH] Do not lose synchronization on truncated packets In current bitstream introduced in commit d0192dca8ab5 ("Update to latest FPGA bitstream") only 1027 bytes are captured when HF0_TRUNC flag is set. HF0_TRUNC can happen either when there is babble packet on the bus or when the gateware incoming ULPI buffer gets full. When HF0_TRUNC is set, the packet size stored in header is guaranteed to be larger than 1027 but only 1027 bytes are actually captured. The next packet data are then incorrectly treated as remainder of the packet and therefore the stream gets out of sync. Fix the issue by respecting gateware maximum captured packet size. --- src/decoder.c | 2 +- tools/sample/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/decoder.c b/src/decoder.c index c204eb2..bea9c2d 100644 --- a/src/decoder.c +++ b/src/decoder.c @@ -71,7 +71,7 @@ int packet_decoder_proc(struct packet_decoder* pd, uint8_t* buf, size_t size) { } } break; case NEED_PACKET_DATA: { - const size_t required_length = pd->packet->size - pd->buf_actual_length; + const size_t required_length = ov_packet_captured_size(pd->packet) - pd->buf_actual_length; const size_t copy = MIN(required_length, end - buf); memcpy(pd->packet->data + pd->buf_actual_length, buf, copy); diff --git a/tools/sample/main.c b/tools/sample/main.c index 220a0d8..7e7f3c7 100644 --- a/tools/sample/main.c +++ b/tools/sample/main.c @@ -11,7 +11,7 @@ static void packet_handler(struct ov_packet* packet, void* data) { printf("[%02x] Received %d bytes at %" PRId64 ":", packet->flags, packet->size, packet->timestamp); - for (int i = 0; i < packet->size; ++i) + for (int i = 0; i < ov_packet_captured_size(packet); ++i) printf(" %02x", packet->data[i]); printf("\n"); }