Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
289 views
in Technique[技术] by (71.8m points)

protocols - When do USB Hosts require a zero-length IN packet at the end of a Control Read Transfer?

I am writing code for a USB device. Suppose the USB host starts a control read transfer to read some data from the device, and the amount of data requested (wLength in the Setup Packet) is a multiple of the Endpoint 0 max packet size. Then after the host has received all the data (in the form of several IN transactions with maximum-sized data packets), will it initiate another IN transaction to see if there is more data even though there can't be more?

Here's an example sequence of events that I am wondering about:

  1. USB enumeration process: max packet size on endpoint 0 is reported to be 64.
  2. SETUP-DATA-ACK transaction starts a control read transfer, wLength = 128.
  3. IN-DATA-ACK transaction delivers first 64 bytes of data to host.
  4. IN-DATA-ACK transaction delivers last 64 bytes of data to host.
  5. IN-DATA-ACK with zero-length DATA packet? Does this transaction ever happen?
  6. OUT-DATA-ACK transaction completes Status Phase of the transfer; transfer is over.

I tested this on my computer (Windows Vista, if it matters) and the answer was no: the host was smart enough to know that no more data can be received from the device, even though all the packets sent by the device were full (maximum size allowed on Endpoint 0). I'm wondering if there are any hosts that are not smart enough, and will try to perform another IN transaction and expect to receive a zero-length data packet.

I think I read the relevant parts of the USB 2.0 and USB 3.0 specifications from usb.org but I did not find this issue addressed. I would appreciate it if someone can point me to the right section in either of those documents.

I know that a zero-length packet can be necessary if the device chooses to send less data than the host requested in wLength.

I know that I could make my code flexible enough to handle either case, but I'm hoping I don't have to.

Thanks to anyone who can answer this question!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Read carefully USB specification:

The Data stage of a control transfer from an endpoint to the host is complete when the endpoint does one of the following:

  • Has transferred exactly the amount of data specified during the Setup stage
  • Transfers a packet with a payload size less than wMaxPacketSize or transfers a zero-length packet

So, in your case, when wLength == transfer size, answer is NO, you don't need ZLP.

In case wLength > transfer size, and (transfer size % ep0 size) == 0 answer is YES, you need ZLP.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...