DrCachetes
DrCachetes

Reputation: 954

How to identify the data bytes used for CRC(checksum) in an USB ISO-Transfer?

I'm using libusb to get data in real time from an USB audio device. My Max Packet Size is of 196 bytes. I know that 4 of that bytes are added for the checksum. I want to identify the bytes used to the checksum so I can store only the usefull data of the transfer but I have some doubts:

1) Are these bytes added at the beginning or at the end of the packet?

2) Do these bytes have a reserved value?

3) In case of losing some data bytes in the transfer. What considerations should I use for the bytes used for the checksum?

EDIT 1

I have these doubts because my specific device has an Interface and alt-setting that works with a sample rate of 48 KHz, 2 channels, 16 bits depth and with a Max Packet Size of 196 bytes.

So there are 48 samples * 2 of two channels * 2 bytes = 192 bytes

So then my packets should be of 192 bytes but when I set my device to work with that interface and alt-setting I start to receive packets of 196 bytes. The corresponding interface and alt-setting for the OUT ISO Endpoint works at a sample rate of 48 KHz, 2 channels, 16 bits depth and with a Max Packet Size of 192 bytes.

4) If these bytes are not from the checksum why are these bytes being added?

Upvotes: 0

Views: 971

Answers (1)

Shaibal
Shaibal

Reputation: 925

enter image description here

I know that 4 of that bytes are added for the checksum

Wrong. CRC is 2 bytes for data packet and 5 bits for token packet. Also CRC is never stored/forwarded in/to the user buffer. It gets stripped by the controller during verification of the CRC. So you are not going to see the CRC at all. But if you still want to see the CRC, attach a USB packet analyzer and have a look at the trace.

1) Are these bytes added at the beginning or at the end of the packet?

2 bytes are added at the end.

2) Do these bytes have a reserved value?

No. Its calculated based on the content of the data packet

3) In case of losing some data bytes in the transfer. What considerations should I use for the bytes used for the checksum?

If you are losing some bytes after CRC is already calculated, you are going to get USB transaction error (CRC mismatch from the host). The same transaction will be retried by the host.

PS - I assumed you are using high speed device

Upvotes: 1

Related Questions