Writing zero length bulk packets

The example Walter Oney gives in his book on writing WDM drivers ,
“Programming the Windows Driver Model”. Edition 1. Does not support writing
zero length bulk packets.

Specifically in his StartIo routine he checks for a length = 0 and bypasses
the bulk send.

Modifying the StartIo routine to send this packet, in my case does not
work, as the Irp MdlAddress is zero.

Has anybody modified this code to support ZLP and if so could they please
indicate where I should look or better still provide an example

Thanks in advance
Stewart

I believe zero-length bulk OUT packets are simply illegal in the USB
specification. What are you trying to accomplish?

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of stewart hamilton
Sent: Tuesday, November 29, 2005 4:48 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Writing zero length bulk packets

The example Walter Oney gives in his book on writing WDM drivers ,
“Programming the Windows Driver Model”. Edition 1. Does not support writing
zero length bulk packets.

Specifically in his StartIo routine he checks for a length = 0 and bypasses
the bulk send.

Modifying the StartIo routine to send this packet, in my case does not work,
as the Irp MdlAddress is zero.

Has anybody modified this code to support ZLP and if so could they please
indicate where I should look or better still provide an example

Thanks in advance
Stewart


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stonestreetone.com To
unsubscribe send a blank email to xxxxx@lists.osr.com

They are perfectly legal and in fact are one of the fundamental ways of
indicated the termination of a bulk transfer.

Basically by detecting a short packet ( one which has less bytes than the
maximum packet size specified for the pipe) you can determine when a
transfer is complete. To handle the case where the message is an
exact multiple of the maximum packet size, one completes the message
with packet of zero length … which is the ultimate in a “short packet”.

I believe zero-length bulk OUT packets are simply illegal in the USB
specification. What are you trying to accomplish?

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of stewart hamilton
Sent: Tuesday, November 29, 2005 4:48 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Writing zero length bulk packets

The example Walter Oney gives in his book on writing WDM drivers ,
“Programming the Windows Driver Model”. Edition 1. Does not support writing
zero length bulk packets.

Specifically in his StartIo routine he checks for a length = 0 and bypasses
the bulk send.

Modifying the StartIo routine to send this packet, in my case does not work,
as the Irp MdlAddress is zero.

Has anybody modified this code to support ZLP and if so could they please
indicate where I should look or better still provide an example

Thanks in advance
Stewart


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stonestreetone.com To
unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@varianinc.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

stewart hamilton wrote:

They are perfectly legal and in fact are one of the fundamental ways
of indicated the termination of a bulk transfer.

Basically by detecting a short packet ( one which has less bytes than
the maximum packet size specified for the pipe) you can determine when
a transfer is complete. To handle the case where the message is an
exact multiple of the maximum packet size, one completes the
message with packet of zero length … which is the ultimate in a
“short packet”.

Yes, but that’s all handled for you automatically at levels below you.
If you issue a bulk write URB writing 512 bytes on a pipe with a max
transfer size of 64, the host controller driver will chop it up into 9
transfers: 8 of 64 bytes, 1 of 0 bytes.

There is absolutely no point in doing a 0-byte write URB, and that’s why
the stock drivers disallow it.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

You are describing the device sending the zero length packet to the
host. That is fine and legal. The host sending the device a zero
length packet is not really

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of stewart hamilton
Sent: Tuesday, November 29, 2005 5:05 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Writing zero length bulk packets

They are perfectly legal and in fact are one of the fundamental ways of

indicated the termination of a bulk transfer.

Basically by detecting a short packet ( one which has less bytes than
the
maximum packet size specified for the pipe) you can determine when a
transfer is complete. To handle the case where the message is an
exact multiple of the maximum packet size, one completes the message
with packet of zero length … which is the ultimate in a “short
packet”.

I believe zero-length bulk OUT packets are simply illegal in the USB
specification. What are you trying to accomplish?

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of stewart
hamilton
Sent: Tuesday, November 29, 2005 4:48 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Writing zero length bulk packets

The example Walter Oney gives in his book on writing WDM drivers ,
“Programming the Windows Driver Model”. Edition 1. Does not support
writing
zero length bulk packets.

Specifically in his StartIo routine he checks for a length = 0 and
bypasses
the bulk send.

Modifying the StartIo routine to send this packet, in my case does not
work,
as the Irp MdlAddress is zero.

Has anybody modified this code to support ZLP and if so could they
please
indicate where I should look or better still provide an example

Thanks in advance
Stewart


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stonestreetone.com To
unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as:
xxxxx@varianinc.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

To quote  the USB 2.0 specifications

5.8.3 Bulk Transfer Packet Size
Constraints

An endpoint for bulk
transfers specifies the maximum data payload size that the endpoint can
accept from

or transmit to the bus. The USB defines the allowable maximum bulk data
payload sizes to be only 8, 16,

32, or 64 bytes for full-speed endpoints and 512 bytes for high-speed
endpoints. A low-speed device must

not have bulk endpoints. This maximum applies to the data payloads of the
data packets; i.e., the size

specified is for the data field of the packet as defined in Chapter 8,
not including other protocol-required

information.

A bulk endpoint is designed to support a maximum data payload size. A
bulk endpoint reports in its

configuration information the value for its maximum data payload size.
The USB does not require that data

payloads transmitted be exactly the maximum size; i.e., if a data payload
is less than the maximum, it does

not need to be padded to the maximum size.

All Host Controllers are required to have support for 8-, 16-, 32-, and
64-byte maximum packet sizes for

full-speed bulk endpoints and 512 bytes for high-speed bulk endpoints. No
Host Controller is required to

support larger or smaller maximum packet sizes.

During configuration, the USB System Software reads the endpoint?s
maximum data payload size and

ensures that no data payload will be sent to the endpoint that is larger
than the supported size.

An endpoint must always transmit data payloads with a data field less
than or equal to the endpoint?s

reported wMaxPacketSize value. When a bulk IRP involves more data
than can fit in one maximum-sized

data payload, all data payloads are required to be maximum size except
for the last data payload, which will

contain the remaining data. A bulk transfer is complete when the endpoint
does one of the following:

.
Has transferred exactly the
amount of data expected

.
Transfers a packet with a
payload size less than wMaxPacketSize or transfers a zero-length
packet

When a bulk transfer is complete, the Host Controller retires the
current IRP and advances to the next IRP.

If a data payload is received that is larger than expected, all pending
bulk IRPs for that endpoint will be

aborted/retired.

The  zero-length packet   packet is valid for
either  the host or the device   to send

You are describing the device
sending the zero length packet to the

host.  That is fine and legal.  The host sending the device a
zero

length packet is not really

d

-----Original Message-----

From: xxxxx@lists.osr.com

[
mailto:xxxxx@lists.osr.com
] On Behalf Of stewart
hamilton

Sent: Tuesday, November 29, 2005 5:05 PM

To: Windows System Software Devs Interest List

Subject: RE: [ntdev] Writing zero length bulk packets

They are perfectly legal and in fact are one of the fundamental
ways  of

indicated the termination of a bulk transfer.

Basically  by detecting a short packet ( one which has less bytes
than

the

maximum packet size specified for the pipe) you can determine when a

transfer is complete. To handle the case where the message is an

exact  multiple of the  maximum packet size,  one
completes the message

with  packet of zero length … which is the ultimate in a
"short

packet".

>I believe zero-length bulk OUT packets are simply illegal in the
USB

>specification.  What are you trying to accomplish?

>

>– arlie

>

>

>-----Original Message-----

>From: xxxxx@lists.osr.com

>[
mailto:xxxxx@lists.osr.com
] On Behalf Of stewart

hamilton

>Sent: Tuesday, November 29, 2005 4:48 PM

>To: Windows System Software Devs Interest List

>Subject: [ntdev] Writing zero length bulk packets

>

>The example Walter Oney gives in his book on writing WDM drivers
,

>“Programming the Windows Driver Model”. Edition 1. Does not
support

writing

>zero length bulk packets.

>

>Specifically in his StartIo routine he checks for a length = 0
and

bypasses

>the bulk send.

>

>Modifying the StartIo routine to send this packet, in my case does
not

work,

>as the Irp MdlAddress is zero.

>

>Has anybody modified this code to support ZLP and if so could
they

please

>indicate where I should look or better still provide an example

>

>Thanks in advance

>Stewart

>

>

>

>—

>Questions? First check the Kernel Driver FAQ at

>
http://www.osronline.com/article.cfm?id=256

>

>You are currently subscribed to ntdev as: xxxxx@stonestreetone.com
To

>unsubscribe send a blank email to
xxxxx@lists.osr.com

>

>

>

>

>—

>Questions? First check the Kernel Driver FAQ at

>
http://www.osronline.com/article.cfm?id=256

>

>You are currently subscribed to ntdev as:

xxxxx@varianinc.com

>To unsubscribe send a blank email to
xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at


http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@microsoft.com

To unsubscribe send a blank email to
xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at

http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’

To unsubscribe send a blank email to xxxxx@lists.osr.com

Hmmmm. So it is. My apologies.

– arlie

> Transfers a packet with a payload size less than wMaxPacketSize or
transfers a zero-length packet
When a bulk transfer is complete, the Host Controller retires the current
IRP and advances to the next IRP.
If a data payload is received that is larger than expected, all pending bulk
IRPs for that endpoint will be
aborted/retired.

The zero-length packet packet is valid for either the host or the device
to send

stewart hamilton wrote:

To quote the USB 2.0 specifications

*5.8.3 Bulk Transfer Packet Size Constraints
*… A bulk transfer is complete when the endpoint does one of the
following:
. Has transferred exactly the amount of data expected
.* **Transfers a packet with a payload size less than /wMaxPacketSize
/or transfers a zero-length packet
*When a bulk transfer is complete, the Host Controller retires the
current IRP and advances to the next IRP.
If a data payload is received that is larger than expected, all
pending bulk IRPs for that endpoint will be
aborted/retired.

The zero-length packet packet is valid for either the host or the
device to send

This is discussing the protocol at a very different level from what you
asked about. You asked about requesting a zero-length bulk transfer via
a URB to the host controller driver. A bulk transfer is made up of a
number of packets, the last of which must be short (or zero). A
zero-length PACKET is valid on the bus wire, and has the specific
meaning described in the bus spec above. The host controller driver
will make sure such a packet gets sent when it is necessary.

A zero-length TRANSFER, which is what you requested, is not valid.
That’s not part of the USB bus spec – it is an artifact of the design
of USBD.SYS.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Hi Tim.

Am I missing something.

From my understanding Microsoft request that transfers be broken down into
4K or smaller chucks when being passed down to the host controller driver.
Consequently the host controller driver does not know when a message
transfer is complete. So does NOT insert a zero length packet at the end
of each transfer. I have verified this using a CATC USB inspector.

Be nice if there was a way of informing the host controller driver that the
message transfer was complete so that the host controller driver did insert
the Zero length packet automatically

Stewart

stewart hamilton wrote:

>To quote the USB 2.0 specifications
>
>*5.8.3 Bulk Transfer Packet Size Constraints
>*… A bulk transfer is complete when the endpoint does one of the
>following:
>. Has transferred exactly the amount of data expected
>.* **Transfers a packet with a payload size less than /wMaxPacketSize /or
>transfers a zero-length packet
>*When a bulk transfer is complete, the Host Controller retires the
>current IRP and advances to the next IRP.
>If a data payload is received that is larger than expected, all pending
>bulk IRPs for that endpoint will be
>aborted/retired.
>
>The zero-length packet packet is valid for either the host or the
>device to send

This is discussing the protocol at a very different level from what you
asked about. You asked about requesting a zero-length bulk transfer via a
URB to the host controller driver. A bulk transfer is made up of a number
of packets, the last of which must be short (or zero). A zero-length
PACKET is valid on the bus wire, and has the specific meaning described in
the bus spec above. The host controller driver will make sure such a
packet gets sent when it is necessary.

A zero-length TRANSFER, which is what you requested, is not valid.
That’s not part of the USB bus spec – it is an artifact of the design of
USBD.SYS.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@varianinc.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

I dealt with this issue on my own driver and with the usb device I was talking to (including “tuning” the transfer size to increase throughput performance):

The host controller driver can’t determine when to insert a ZLP because it depends on how much the usb device expects to receive.

For example, if the usb device expects to receive 4k of data and only 64 bytes (max packet size for usb 1.1 bulk) are sent to it from XP, it (the usb device’s usb controller, actually) will keep waiting for data. This is why the XP driver has to send a ZLP - to tell the usb device (the usb device’s usb controller) that the transfer is done (it’s a short transfer).

However, if the usb device expects to receive only 64 bytes of data and 64 bytes are sent to it from XP, it will know the transfer is complete (since it received all the data it expected). In this case no ZLP has to be sent from the XP driver to indicate a transfer complete.

So, the decision as to whether ZLP need to be sent by the XP driver (and similarly by the usb device for bulk in operations) is dependent on the implementation of the driver and the usb device software - what they decide the expected transfer sizes are.

For my particular scenario, both the xp driver and the usb device device expected 4k byte transfers. For transfers that were a multiple of 64 but less than 4K, both sides had to send a ZLP to complete the transfer.

If the usb device didn’t send the ZLP, the XP host controller driver (the OS driver) would wait around until more data was sent. I needed the usb devcie to send the ZLP so my driver could get the 64 bytes as soon as it was received.

If the expected transfer size was only 64 bytes for both the xp driver and the usb device, no ZLP packet would need to be sent, because the packet size = the expected transfer size. But the drawback would be performance. You trade off the need for ZLPs (an overhead) for a bigger transfer size.

Hope this helps…

----- Original Message -----
From: stewart hamiltonmailto:xxxxx
To: Windows System Software Devs Interest Listmailto:xxxxx
Sent: Wednesday, November 30, 2005 5:40 PM
Subject: Re: [ntdev] Writing zero length bulk packets

Hi Tim.

Am I missing something.

From my understanding Microsoft request that transfers be broken down into
4K or smaller chucks when being passed down to the host controller driver.
Consequently the host controller driver does not know when a message
transfer is complete. So does NOT insert a zero length packet at the end
of each transfer. I have verified this using a CATC USB inspector.

Be nice if there was a way of informing the host controller driver that the
message transfer was complete so that the host controller driver did insert
the Zero length packet automatically

Stewart

>stewart hamilton wrote:
>
>>To quote the USB 2.0 specifications
>>
>>5.8.3 Bulk Transfer Packet Size Constraints
>>
… A bulk transfer is complete when the endpoint does one of the
>>following:
>>. Has transferred exactly the amount of data expected
>>.* **Transfers a packet with a payload size less than /wMaxPacketSize /or
>>transfers a zero-length packet
>>*When a bulk transfer is complete, the Host Controller retires the
>>current IRP and advances to the next IRP.
>>If a data payload is received that is larger than expected, all pending
>>bulk IRPs for that endpoint will be
>>aborted/retired.
>>
>>The zero-length packet packet is valid for either the host or the
>>device to send
>
>
>This is discussing the protocol at a very different level from what you
>asked about. You asked about requesting a zero-length bulk transfer via a
>URB to the host controller driver. A bulk transfer is made up of a number
>of packets, the last of which must be short (or zero). A zero-length
>PACKET is valid on the bus wire, and has the specific meaning described in
>the bus spec above. The host controller driver will make sure such a
>packet gets sent when it is necessary.
>
>A zero-length TRANSFER, which is what you requested, is not valid.
>That’s not part of the USB bus spec – it is an artifact of the design of
>USBD.SYS.
>
>–
>Tim Roberts, xxxxx@probo.commailto:xxxxx
>Providenza & Boekelheide, Inc.
>
>
>
>—
>Questions? First check the Kernel Driver FAQ at
>http://www.osronline.com/article.cfm?id=256
>
>You are currently subscribed to ntdev as: xxxxx@varianinc.commailto:xxxxx
>To unsubscribe send a blank email to xxxxx@lists.osr.commailto:xxxxx


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256http:

You are currently subscribed to ntdev as: xxxxx@msn.commailto:xxxxx
To unsubscribe send a blank email to xxxxx@lists.osr.commailto:xxxxx</mailto:xxxxx></mailto:xxxxx></http:></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>