ransh
ransh

Reputation: 1712

What is "zero-length packet"?

USB standard mentions writing "zero-length" packets in some scenarios.

Can anyone please explain what is the meaning of "zero-length" packets in USB terminology ?

What is "short packet" ? (seems that both "short packet" and "zero-length packet" are mentioned together)

Upvotes: 6

Views: 7589

Answers (1)

Shaibal
Shaibal

Reputation: 925

Both of the terminologies are used for transaction completion mechanism. The maximum size of data packets can be derived from bMaxPacketSize stored in Endpoint descriptors. When data packet is less than that, its called a Short Packet. Similarly when you can send a data packet with length Zero.

Now the question is "Why". Lets discuss that.

Reasons for Short packets -

1 - As per USB specification, When the host or device receives a data packet with packet length less than maximum packet size, it shall consider the transfer is complete and no more data packet is left to receive.

2 - This is always the case for Bulk transfer (Mass storage devices). You do not always ask data with length multiple of MaxPacketSize. So the last packet will always be less than max packet size. Consider you want 1025 bytes of data from bulk endpoint whose max packet size is 1024 bytes.

First Data Packet = 1024 bytes Seconds Data Packet = 1 byte (Short Packet).

This way the host will know that the data transfer is complete.

Reason for Zero length packet -

1 - Like Short packet, zero length packet is also used for transaction complete. Consider you want to send 2048 bytes of bulk data.

First data packet = 1024 bytes Second data packet = 1024 bytes.

Now the problem is, both are equal to max packet size. The device will not understand that the transfer is complete. Then you send a zero length packet.

Third data packet = 0 bytes

This will make the transfer complete and device can then start processing the data.

2 - Zero length packet is also used in control transfer during status stage to notify successful completion.

Upvotes: 8

Related Questions