USB Bulk-Only Transport 批量传输协议规范

前言

对于 包(Packet) 组成 事务(Transaction) ,事务组成 传输(Transfer) 等的概念不在本篇文章讲述,需要的请前往文章:USB 协议数据包的层次结构和组成 进行阅读学习。


一、规格概述及范围

1.1 Scope

范围

A familiarity with the USB 1.0 and 1.1 Specifications and the USB Mass Storage Class Specification Overview is assumed.
假定熟悉 USB 1.0 和 1.1 规范和 USB 大容量存储类规范概述。

This specification addresses Bulk-Only Transport, or in other words, transport of command, data, and status occurring solely via Bulk endpoints (not via Interrupt or Control endpoints).
这个规范处理的是大容量传输,换句话说,命令、数据和状态的传输仅通过大容量端点发生(不通过中断或控制端点)。

This specification only uses the default pipe to clear a STALL condition on the Bulk endpoints and to issue class-specific requests as defined below. This specification does not require the use of an Interrupt endpoint.
本规范仅使用默认管道来清除 Bulk 端点上的 STALL 条件,并发出以下定义的特定于类的请求。这个规范不要求使用中断端点。

This specification defines support for logical units that share common device characteristics. Although this feature provides the support necessary to allow like mass storage devices to share a common USB interface descriptor, it is not intended to be used to implement interface bridge devices.
该规范定义了对共享公共设备特征的逻辑单元的支持。虽然这个特性提供了必要的支持,允许大容量存储设备共享一个通用的USB接口描述符,但它并不打算用于实现接口桥接设备。


二、名词解释

  • Command Block Wrapper (CBW)
    A packet containing a command block and associated information.
    一种包含命令块和相关信息的数据包。

  • Command Status Wrapper (CSW)
    A packet containing the status of a command block.
    一种包含命令块状态的数据包。

  • Data-In
    Indicates a transfer of data IN from the device to the host.
    表示将数据从设备传入(IN)到主机。

  • Data-Out
    Indicates a transfer of data OUT from the host to the device.
    表示将数据从主机传出(OUT)到设备。

  • Device Request
    Requests from the host to the device using the default pipe.
    使用默认管道从主机到设备的请求。

  • Phase Error
    An error returned by the device indicating that the results of processing further CBWs will be indeterminate until the device is reset.
    设备返回的错误,表明在设备复位之前,处理进一步CBW的结果将是不确定的。

  • Processed
    Data received and controlled internally by the device to the point that the host need no longer be concerned about it.
    数据由设备在内部接收和控制,以至于主机不再需要担心它。

  • Relevant
    The amount of the data sent to the host by the device that is significant.
    设备发送到主机的重要数据量。

  • Reset Recovery
    An error recovery procedure by which the host prepares the device for further CBWs.
    一种错误恢复过程,主机通过该过程为进一步的CBW准备设备。

  • Thin Diagonal
    Cases where the host and device are in complete agreement about the data transfer. See Chapter 6 - Host/Device Data Transfers, for additional information regarding error cases and the “thin diagonal.”
    主机和设备在数据传输方面完全一致的情况。请参阅第 6 章 - 主机/设备数据传输,了解有关错误情况和“细对角线”的更多信息。


三、功能特点

3.1 Bulk-Only Mass Storage Reset (class-specific request)

仅批量大容量存储重置(特定于类的请求)

This request is used to reset the mass storage device and its associated interface.
此请求用于重置大容量存储设备及其相关接口。

This class-specific request shall ready the device for the next CBW from the host.
此特定于类的请求应使设备为来自主机的下一个 CBW 做好准备。

The host shall send this request via the default pipe to the device. The device shall preserve the value of its bulk data toggle bits and endpoint STALL conditions despite the Bulk-Only Mass Storage Reset.
主机将通过默认管道将此请求发送到设备。尽管大容量存储复位,设备仍应保留其大容量数据切换位的值和端点停顿条件。

The device shall NAK the status stage of the device request until the Bulk-Only Mass Storage Reset is complete.
设备应 NAK 设备请求的状态阶段,直到仅批量大容量存储重置完成。

To issue the Bulk-Only Mass Storage Reset the host shall issue a device request on the default pipe of:
要发出仅批量大容量存储重置,主机应在以下默认管道上发出设备请求:

• bmRequestType: Class, Interface, host to device
• bRequest field set to 255 (FFh)
• wValue field set to 0
• wIndex field set to the interface number
• wLength field set to 0

USB Bulk-Only Transport 批量传输协议规范_第1张图片


3.2 Get Max LUN (class-specific request)

获取最大 LUN(特定于类的请求)

The device may implement several logical units that share common device characteristics.
设备可以实现多个逻辑单元,这些逻辑单元具有共同的设备特性。

The host uses bCBWLUN (see 5.1 Command Block Wrapper (CBW)) to designate which logical unit of the device is the destination of the CBW.
主机使用 bCBWLUN(请参阅 5.1 命令块包装器 (CBW))来指定设备的哪个逻辑单元是 CBW 的目标。

The Get Max LUN device request is used to determine the number of logical units supported by the device. Logical Unit Numbers on the device shall be numbered contiguously starting from LUN 0 to a maximum LUN of 15 (Fh).
Get Max LUN 设备请求用于确定设备支持的逻辑单元数。设备上的“逻辑单元号”应从 LUN 0 开始连续编号,最多为 15 (Fh)。

To issue a Get Max LUN device request, the host shall issue a device request on the default pipe of :
要发出 Get Max LUN 设备请求,主机应该在默认管道上发出设备请求:

• bmRequestType: Class, Interface, device to host
• bRequest field set to 254 (FEh)
• wValue field set to 0
• wIndex field set to the interface number
• wLength field set to 1

USB Bulk-Only Transport 批量传输协议规范_第2张图片

The device shall return one byte of data that contains the maximum LUN supported by the device.
设备将返回一个字节的数据,其中包含设备支持的最大LUN。

For example, if the device supports four LUNs then the LUNs would be numbered from 0 to 3 and the return value would be 3. If no LUN is associated with the device, the value returned shall be 0. The host shall not send a command block wrapper (CBW) to a non-existing LUN.
例如,如果设备支持四个 LUN,则 LUN 的编号将从 0 到 3,返回值将为 3。 如果没有 LUN 与设备关联,则返回的值应为 0。 主机不得将命令块包装 (CBW) 发送到不存在的 LUN。

Devices that do not support multiple LUNs may STALL this command.
对于不支持多个 lun 的设备,可能会导致该命令执行失败。


3.3 Host/Device Packet Transfer Order

主机/设备数据包传输顺序

The host shall send the CBW before the associated Data-Out, and the device shall send Data-In after the associated CBW and before the associated CSW. The host may request Data-In or CSW before sending the associated CBW.
主机应在相关的 Data-Out 之前发送 CBW,设备应在相关的 CBW 之后、在相关的 CSW 之前发送 Data-In。主机可以在发送相关的 CBW 之前请求 Data-In 或 CSW。

If the dCBWDataTransferLength is zero, the device and the host shall transfer no data between the CBW and the associated CSW.
如果 dCBWDataTransferLength 为 0,则设备和主机不能在 CBW 和关联的 CSW 之间传输数据。


3.4 Command Queuing

命令队列

The host shall not transfer a CBW to the device until the host has received the CSW for any outstanding CBW.
在主机收到任何未完成CBW的CSW之前,主机不应将CBW传输到设备。

If the host issues two consecutive CBWs without an intervening CSW or reset, the device response to the second CBW is indeterminate.
如果主机连续发出两个 CBW,中间没有 CSW 或复位,则设备对第二个 CBW 的响应是不确定的。


3.5 Bi-Directional Command Protocol

双向命令协议

This specification does not provide for bi-directional data transfer in a single command.
此规范不提供单个命令中的双向数据传输。


四、Standard Descriptors

标准描述符

The device shall support the following standard USB descriptors:
设备应支持以下标准 USB 描述符:

Device. Each USB device has one device descriptor (per USB Specification).
每个 USB 设备都有一个设备描述符(根据 USB 规范)。

Configuration. Each USB device has one default configuration descriptor, which supports at least one interface.
每个 USB 设备都有一个默认配置描述符,该描述符至少支持一个接口。

Interface. The device shall support at least one interface, known herein as the Bulk-Only Data Interface. Some devices may support additional interfaces, to provide other capabilities.
设备至少支持一个接口,在这里称为大容量专用数据接口。一些设备可能支持额外的接口,以提供其他功能。

Endpoint. The device shall support the following endpoints, in addition to the default pipe that is required of all USB devices:
除了所有USB设备所需的默认管道外,该设备还应支持以下端点:
(a) Bulk-In endpoint 批量传入端点
(b) Bulk-Out endpoint 批量输出端点

Some devices may support additional endpoints, to provide other capabilities. The host shall use the first reported Bulk-In and Bulk-Out endpoints for the selected interface.
一些设备可能支持额外的端点,以提供其他功能。主机应为所选接口使用第一个报告的 Bulk-In 和 Bulk-Out 端点。

String.
The device shall supply a unique serial number as detailed in 4.1.1 - Serial Number.
设备应提供一个唯一的序列号,详见4.1.1 -序列号。

This specification defines no class-specific descriptors.
此规范未定义特定于类的描述符。

The rest of this section describes the standard USB device, configuration, interface, endpoint, and string descriptors for the device. For superseding information about these and other standard descriptors, see Chapter 9, “USB Device Framework,” of the USB Specification.
本节的其余部分介绍设备的标准 USB 设备、配置、接口、端点和字符串描述符。有关这些和其他标准描述符的替代信息,请参见 USB 规范的第 9 章“USB 设备框架”。


4.1 Device Descriptor

设备描述符

Each USB device has one device descriptor (per USB Specification). The device shall specify the device class and subclass codes in the interface descriptor, and not in the device descriptor.
每个 USB 设备都有一个设备描述符(根据 USB 规范)。设备应在接口描述符中指定设备类和子类代码,而不是在设备描述符中指定。
USB Bulk-Only Transport 批量传输协议规范_第3张图片
NOTE: Information in this table is from the USB Specification version 1.1 table 9-7. Bold text has been added for clarifications when using these descriptors with this specification.
注:此表中的信息来自 USB 规范版本 1.1 表 9-7。 添加了粗体文本,以便在将这些描述符与此规范一起使用时进行说明。


4.1.1 Serial Number

The iSerialNumber field shall be set to the index of the string descriptor that contains the serial number. The serial number shall contain at least 12 valid digits, represented as a UNICODE string. The last 12 digits of the serial number shall be unique to each USB idVendor and idProduct pair.
iSerialNumber 字段应该设置为包含序列号的字符串描述符的索引。序列号应包含至少 12 位有效数字,以UNICODE 字符串表示。序列号的最后 12 位数字对于每个 USB idVendor 和 idProduct 对必须是唯一的。

The host may generate a globally unique identifier by concatenating the 16 bit idVendor, the 16 bit idProduct and the value represented by the last 12 characters of the string descriptor indexed by iSerialNumber.
主机可以通过连接16位idVendor、16位idProduct和由iSerialNumber索引的字符串描述符的最后12个字符表示的值来生成全局唯一标识符。

The field iSerialNumber is an index to a string descriptor and does not contain the string itself. An example format for the String descriptor is shown below.
字段 iSerialNumber 是字符串描述符的索引,不包含字符串本身。下面显示了 String 描述符的示例格式

USB Bulk-Only Transport 批量传输协议规范_第4张图片


4.1.2 Valid Serial Number Characters

The following table defines the valid characters that the device shall use for the serial number.
下表定义了设备用于序列号的有效字符。

USB Bulk-Only Transport 批量传输协议规范_第5张图片


4.2 Configuration Descriptor

配置描述符

USB Bulk-Only Transport 批量传输协议规范_第6张图片

NOTE: Information in this table is from the USB Specification version 1.1 table 9-8. Bold text has been added for clarifications when using these descriptors with this specification.
注:本表中的信息来自USB规范版本1.1表9-8。在此规范中使用这些描述符时,添加了粗体文本以进行澄清。


4.3 Interface Descriptors

接口描述符

The device shall support at least one interface, known herein as the Bulk-Only Data Interface. The Bulk-Only Data Interface uses three endpoints.
设备至少支持一个接口,在这里称为大容量专用数据接口。大容量数据接口使用三个端点。

Composite mass storage devices may support additional interfaces, to provide other features such as audio or video capabilities. This specification does not define such interfaces.
复合大容量存储设备可以支持额外的接口,以提供其他功能,如音频或视频功能。本规范没有定义这样的接口。

The interface may have multiple alternate settings. The host shall examine each of the alternate settings to look for the bInterfaceProtocol and bInterfaceSubClass it supports optimally.
接口可能有多个可选设置。主机应该检查每一个备用设置,以寻找它最支持的 bInterfaceProtocol 和 bInterfaceSubClass。

USB Bulk-Only Transport 批量传输协议规范_第7张图片
NOTE: Information in this table is from the USB Specification version 1.1 table 9-9. Bold text has been added for clarifications when using these descriptors with this specification.
注:本表中的信息来自USB规范版本1.1表9-9。添加粗体文本,用于在使用这些描述符时进行澄清。


4.4 Endpoint Descriptors

端点描述符

The device shall support at least three endpoints: Control, Bulk-In and Bulk-Out.
设备至少支持三个端点: 控制、大容量输入和大容量输出。

Each USB device defines a Control endpoint (Endpoint 0). This is the default endpoint and does not require a descriptor.
每个 USB 设备定义一个控制端点(端点0)。这是默认端点,不需要描述符。


4.4.1 Bulk-In Endpoint

The Bulk-In endpoint is used for transferring data and status from the device to the host.
Bulk-In 端点用于将数据和状态从设备传输到主机。

USB Bulk-Only Transport 批量传输协议规范_第8张图片


4.4.2 Bulk-Out Endpoint

The Bulk-Out endpoint is used for transferring command and data from the host to the device.
Bulk-Out 端点用于将命令和数据从主机传输到设备。

USB Bulk-Only Transport 批量传输协议规范_第9张图片


五、Command/Data/Status Protocol

命令/数据/状态协议

Figure 1 - Command/Data/Status Flow shows the flow for Command Transport, Data-In, Data-Out and Status Transport.
图1 -命令/数据/状态流显示了命令传输、数据输入、数据输出和状态传输的流程。

The following sections define Command and Status Transport. Figure 2 - Status Transport Flow shows a detailed diagram of Status Transport. The following sections outline the various conditions for host/device communication, possible errors, and recovery procedures.
以下部分定义了命令和状态传输。图2 -状态传输流显示了状态传输的详细图。以下部分概述了主机/设备通信的各种条件、可能的错误和恢复过程。

USB Bulk-Only Transport 批量传输协议规范_第10张图片


5.1 Command Block Wrapper (CBW)

在这里插入图片描述

如上图所示,Bus Hound 抓取到的 CBW Packet,正好是 31 个字节。
0 ~ 14 字节是 CBW 的前部分,15 字节开始是自定义的命令。


The CBW shall start on a packet boundary and shall end as a short packet with exactly 31 (1Fh) bytes transferred. Fields appear aligned to byte offsets equal to a multiple of their byte size. All subsequent data and the CSW shall start at a new packet boundary. All CBW transfers shall be ordered with the LSB (byte 0) first (little endian). Refer to the USB Specification Terms and Abbreviations for clarification.
CBW应从数据包边界开始,并以传输正好 31(1Fh)字节的短数据包结束。 字段显示为与等于其字节大小的倍数的字节偏移量对齐。 所有后续数据和 CSW 应从新的数据包边界开始。 所有CBW传输应首先使用LSB(字节0)(小端序)进行排序。 有关说明,请参阅 USB 规范术语和缩写。

USB Bulk-Only Transport 批量传输协议规范_第11张图片

dCBWSignature:
Signature that helps identify this data packet as a CBW. The signature field shall contain the value 43425355h (little endian), indicating a CBW.
有助于将此数据包识别为 CBW 的签名。签名字段应包含值 43425355h(小端序),表示 CBW。

dCBWTag:
A Command Block Tag sent by the host. The device shall echo the contents of this field back to the host in the dCSWTag field of the associated CSW. The dCSWTag positively associates a CSW with the corresponding CBW.
主机发送的命令块标签。设备应在相关CSW的dCSWTag字段中将该字段的内容回送到主机。DCSWTag 将 CSW 与相应的 CBW 正向关联。

dCBWDataTransferLength:
The number of bytes of data that the host expects to transfer on the Bulk-In or Bulk-Out endpoint (as indicated by the Direction bit) during the execution of this command. If this field is zero, the device and the host shall transfer no data between the CBW and the associated CSW, and the device shall ignore the value of the Direction bit in bmCBWFlags.
在执行此命令期间,主机期望在 Bulk-In 或 Bulk-Out 端点上传输的数据字节数(由方向位指示)。如果该字段为零,则设备和主机之间不进行数据传输,设备将忽略 bmCBWFlags 中 Direction 位的值。

bmCBWFlags:
The bits of this field are defined as follows:
该字段的位定义如下:
Bit 7 Direction - the device shall ignore this bit if the dCBWDataTransferLength field is zero, otherwise:
位 7 方向 - 如果 dCBWDataTransferLength 字段为零,则设备应忽略此位,否则:
0 = Data-Out from host to the device,
1 = Data-In from the device to the host.
Bit 6 Obsolete. The host shall set this bit to zero.
Bits 5…0 Reserved - the host shall set these bits to zero.

bCBWLUN:
The device Logical Unit Number (LUN) to which the command block is being sent. For devices that support multiple LUNs, the host shall place into this field the LUN to which this command block is addressed. Otherwise, the host shall set this field to zero.
命令块要发送到的设备逻辑单元号(LUN)。对于支持多个 LUN 的设备,主机应将此命令块寻址到的 LUN 放入此字段中。否则,主机应将此字段设置为零。

bCBWCBLength:
The valid length of the CBWCB in bytes. This defines the valid length of the command block. The only legal values are 1 through 16 (01h through 10h). All other values are reserved.
CBWCB 的有效长度,以字节为单位。这定义了命令块的有效长度。唯一合法的值是 1 到 16 (01h 到 10h)。所有其他值都是保留的。

CBWCB:
The command block to be executed by the device. The device shall interpret the first bCBWCBLength bytes in this field as a command block as defined by the command set identified by bInterfaceSubClass. If the command set supported by the device uses command blocks of fewer than 16 (10h) bytes in length, the significant bytes shall be transferred first, beginning with the byte at offset 15 (Fh). The device shall ignore the content of the CBWCB field past the byte at offset (15 + bCBWCBLength - 1).
设备要执行的命令块。 设备将该字段的第一个bCBWCBLength字节解释为命令块,该命令块由bInterfaceSubClass标识的命令集定义。如果设备支持的命令集使用长度小于16 (10h)字节的命令块,则从偏移量为15 (Fh)的字节开始先传输有意义的字节。设备将忽略超过偏移量(15 + bCBWCBLength - 1)的CBWCB字段的内容。


5.2 Command Status Wrapper (CSW)

命令状态包装器

在这里插入图片描述

如上图所示,Bus Hound 抓取到的 CSW Packet,正好是 13 个字节。


The CSW shall start on a packet boundary and shall end as a short packet with exactly 13 (0Dh) bytes transferred. Fields appear aligned to byte offsets equal to a multiple of their byte size. All CSW transfers shall be ordered with the LSB (byte 0) first (little endian). Refer to the USB Specification Terms and Abbreviations for clarification.
CSW 应从数据包边界开始,并以传输正好 13 (0Dh) 字节的短数据包结束。 字段显示为与等于其字节大小的倍数的字节偏移量对齐。 所有 CSW 传输应首先使用 LSB(字节 0)进行排序(小端序)。 有关说明,请参阅 USB 规范术语和缩写。

USB Bulk-Only Transport 批量传输协议规范_第12张图片

dCSWSignature:
Signature that helps identify this data packet as a CSW. The signature field shall contain the value 53425355h (little endian), indicating CSW.
有助于将此数据包标识为 CSW 的签名。签名字段应包含值 53425355h(小端序),表示 CSW。

dCSWTag:
The device shall set this field to the value received in the dCBWTag of the associated CBW.
设备应将此字段设置为相关 CBW 的 dCBWTag 中收到的值。

dCSWDataResidue:
For Data-Out the device shall report in the dCSWDataResidue the difference between the amount of data expected as stated in the dCBWDataTransferLength, and the actual amount of data processed by the device. For Data-In the device shall report in the dCSWDataResidue the difference between the amount of data expected as stated in the dCBWDataTransferLength and the actual amount of relevant data sent by the device. The dCSWDataResidue shall not exceed the value sent in the dCBWDataTransferLength.
对于数据输出,设备应在 dCSWDataResireate 中报告 dCBWDataTransferLength 中规定的预期数据量与设备处理的实际数据量之间的差额。对于数据输入,设备应在 dCSWDataResireate 中报告 dCBWDataTransferLength 中规定的预期数据量与设备发送的实际相关数据量之间的差额。dCSWDataResidue 不应超过 dCBWDataTransferLength 中发送的值。

bCSWStatus:
bCSWStatus indicates the success or failure of the command. The device shall set this byte to zero if the command completed successfully. A non-zero value shall indicate a failure during command execution according to the following table:
BCSWStatus 指示命令的成功或失败。如果命令成功完成,设备应将该字节设置为零。根据下表,非零值应表示命令执行过程中出现故障:

USB Bulk-Only Transport 批量传输协议规范_第13张图片


5.3 Data Transfer Conditions

数据传输条件

This section describes how the host and device remain synchronized.
本节介绍主机和设备如何保持同步。

The host indicates the expected transfer in the CBW using the Direction bit and the dCBWDataTransferLength field. The device then determines the actual direction and data transfer length.
主机使用方向位和dCBWDataTransferLength字段指示CBW中的预期传输。然后,设备确定实际方向和数据传输长度。

The device responds as defined in 6 - Host/Device Data Transfers by transferring data, STALLing endpoints when specified, and returning the appropriate CSW.
设备按照6 -主机/设备数据传输中定义的方式进行响应,通过传输数据,在指定时让端点停止,并返回适当的CSW。


5.3.1 Command Transport

The host shall send each CBW, which contains a command block, to the device via the Bulk-Out endpoint. The CBW shall start on a packet boundary and end as a short packet with exactly 31 (1Fh) bytes transferred.
主机应通过Bulk-Out端点向设备发送每个包含命令块的CBW。CBW开始于包边界,结束于传输的恰好31 (1Fh)字节的短包。

The device shall indicate a successful transport of a CBW by accepting (ACKing) the CBW. If the CBW is not valid see 6.6.1 - CBW Not Valid. If the host detects a STALL of the Bulk-Out endpoint during command transport, the host shall respond with a Reset Recovery (see 5.3.4 - Reset Recovery).
该设备应通过接受(确认) CBW 来指示 CBW 的成功传输。如果 CBW 无效,请参见 6.6.1-CBW 无效。如果主机在命令传输期间检测到批量输出端点停止,主机应以重置恢复响应(参见5.3.4-重置恢复)。


5.3.2 Data Transport

All data transport shall begin on a packet boundary. The host shall attempt to transfer the exact number of bytes to or from the device as specified by the dCBWDataTransferLength and the Direction bit. The device shall respond as specified in 6 - Host/Device Data Transfers.
所有数据传输都应从数据包边界开始。主机应尝试按照 dCBWDataTransferLength 和方向位指定的确切字节数与设备之间传输或从设备传输确切的字节数。设备应按照 6 - 主机/设备数据传输中的规定进行响应。

To report an error before data transport completes and to maximize data integrity, the device may terminate the command by STALLing the endpoint in use (the Bulk-In endpoint during data in, the Bulk-Out endpoint during data out).
为了在数据传输完成之前报告错误并最大化数据完整性,设备可以通过停止正在使用的端点(数据输入期间的大容量输入端点,数据输出期间的大容量输出端点)来终止命令。


5.3.3 Status Transport

USB Bulk-Only Transport 批量传输协议规范_第14张图片
The device shall send each CSW to the host via the Bulk-In endpoint. The CSW shall start on a packet boundary and end as a short packet with exactly 13 (Dh) bytes transferred. Figure 2 - Status Transport Flow defines the algorithm the host shall use for any CSW transfer.
设备应通过批量传入端点将每个 CSW 发送到主机。 CSW 应从数据包边界开始,以传输正好 13 (Dh) 字节的短数据包结束。 图 2 - 状态传输流定义了主机应用于任何 CSW 传输的算法。

The CSW indicates to the host the status of the execution of the command block from the corresponding CBW.
CSW 向主机指示来自相应 CBW 的命令块的执行状态。

The dCSWDataResidue field indicates how much of the data transferred is to be considered processed or relevant. The host shall ignore any data received beyond that which is relevant.
dCSWDataResidue 字段指示传输的数据中有多少被视为已处理或相关。 主机应忽略收到超出相关范围的任何数据。


5.3.3.1 Phase Error

相位误差

The host shall perform a Reset Recovery when Phase Error status is returned in the CSW.
当 CSW 中返回相位错误状态时,主机应执行重置恢复。


5.3.4 Reset Recovery

For Reset Recovery the host shall issue in the following order:
对于重置恢复,主机应按以下顺序发出:
(a) a Bulk-Only Mass Storage Reset
(b) a Clear Feature HALT to the Bulk-In endpoint
© a Clear Feature HALT to the Bulk-Out endpoint


6 Host/Device Data Transfers

6.1 Overview

USB Bulk-Only Transport 批量传输协议规范_第15张图片


A Bulk-Only Protocol transaction begins with the host sending a CBW to the device and attempting to make the appropriate data transfer (In, Out or none). The device receives the CBW, checks and interprets it, attempts to satisfy the host’s request, and returns status via a CSW.
仅批量协议事务开始于,主机向设备发送 CBW 并尝试进行适当的数据传输(传入、传出或无)。设备接收 CBW,检查并解释它,尝试满足主机的请求,并通过 CSW 返回状态。

This section describes in more detail this interaction between the host and the device during normal and abnormal Bulk-Only Protocol transactions.
本节更详细地介绍在正常和非正常的仅批量协议事务期间主机和设备之间的这种交互。


6.2 Valid and Meaningful CBW

有效和有意义的CBW

The host communicates its intent to the device through the CBW. The device performs two verifications on every CBW received. First, the device verifies that what was received is a valid CBW. Next, the device determines if the data within the CBW is meaningful.
主机通过 CBW 将其意图传达给设备。该设备对收到的每个 CBW 执行两次验证。首先,设备验证收到的是有效的 CBW。接下来,设备确定 CBW 中的数据是否有意义。

The device shall not use the contents of the dCBWTag in any way other than to copy its value to the dCSWTag of the corresponding CSW.
除将 dCBWTag 的值复制到相应的 CSW 的 dCSWTag 之外,设备不得以任何方式使用 dCBWTag 的内容。


6.2.1 Valid CBW

The device shall consider the CBW valid when:
设备应在以下情况下认为 CBW 有效:

• The CBW was received after the device had sent a CSW or after a reset,
在设备已发送 CSW 之后,或在重置之后,接收 CBW,
• the CBW is 31 (1Fh) bytes in length,
CBW 长度为 31(1FH)字节
• and the dCBWSignature is equal to 43425355h.
dCBWSignature 等于 43425355h


6.2.2 Meaningful CBW

The device shall consider the contents of a valid CBW meaningful when:
在以下情况下,设备应将有效 CBW 的内容视为有意义:
• no reserved bits are set,
没有设置保留位,
• the bCBWLUN contains a valid LUN supported by the device,
bCBWLUN 包含设备支持的有效 LUN,
• and both bCBWCBLength and the content of the CBWCB are in accordance with bInterfaceSubClass.
bCBWCBLength 和 CBWCB 的内容都符合 bInterfaceSubClass。


6.3 Valid and Meaningful CSW

有效和有意义的CSW

The device generally communicates the results of its attempt to satisfy the host’s request through the CSW.
设备通常通过 CSW 传达其尝试满足主机请求的结果。

The host performs two verifications on every CSW received. First, the host verifies that what was received is a valid CSW Next, the host determines if the data within the CSW is meaningful.
主机对收到的每个 CSW 执行两次验证。首先,主机验证收到的是有效的 CSW 接下来,主机确定 CSW 中的数据是否有意义。


6.3.1 Valid CSW

The host shall consider the CSW valid when:
在以下情况下,主机应认为 CSW 有效:
• the CSW is 13 (Dh) bytes in length,
CSW 的长度为 13 (Dh) 字节
• and the dCSWSignature is equal to 53425355h,
并且 dCSWSignature 等于 53425355h
• the dCSWTag matches the dCBWTag from the corresponding CBW.
dCSWTag 与相应 CBW 的 dCBWTag 匹配。


6.3.2 Meaningful CSW

The host shall consider the contents of the CSW meaningful when:
在下列情况下,主机应认为 CSW 的内容有意义:
either the bCSWStatus value is 00h or 01h and the dCSWDataResidue is less than or equal to dCBWDataTransferLength…
BCSWStatus 值为 00h 或 01h,并且 dCSWDataResi 期值小于或等于 dCBWDataTransferLength …
or the bCSWStatus value is 02h.
或者 bCSWStatus 值为 02h。


6.4 Device Error Handling

设备错误处理

The device may not be able to fully satisfy the host’s request. At the point when the device discovers that it cannot fully satisfy the request, there may be a Data-In or Data-Out transfer in progress on the bus, and the host may have other pending requests. The device may cause the host to terminate such transfers by STALLing the appropriate pipe.

设备可能无法完全满足主机的请求。当设备发现它无法完全满足请求时,总线上可能正在进行数据输入或数据输出传输,并且主机可能有其他挂起的请求。设备可能会导致主机通过停止适当的管道来终止此类传输。

The response of a device to a CBW that is not meaningful is not specified.
没有指定设备对无意义的CBW的响应。

Please note that whether or not a STALL handshake actually appears on the bus depends on whether or not there is a transfer in progress at the point in time when the device is ready to STALL the pipe.
请注意,总线上是否实际出现了STALL握手,这取决于在设备准备让管道暂停的时间点上是否有正在进行的传输。


6.5 Host Error Handling

主机错误处理

If the host receives a CSW which is not valid, then the host shall perform a Reset Recovery. If the host receives a CSW which is not meaningful, then the host may perform a Reset Recovery.
如果主机收到一个无效的CSW,那么主机应该执行一个复位恢复。如果主机收到一个没有意义的CSW,那么主机可能会执行复位恢复。


6.6 Error Classes

错误类

In every transaction between the host and the device, there are four possible classes of errors. These classes are not always independent of each other and may occur at any time during the transaction.
在主机和设备之间的每个事务中,都有四种可能的错误类别。 这些类并不总是彼此独立,并且可能在事务期间的任何时间发生。


6.6.1 CBW Not Valid

If the CBW is not valid, the device shall STALL the Bulk-In pipe. Also, the device shall either STALL the Bulk-Out pipe, or the device shall accept and discard any Bulk-Out data. The device shall maintain this state until a Reset Recovery.
如果CBW无效,则设备应 STALL Bulk-In 管道。此外,设备应该 STALL Bulk-Out 管道,或者设备应该接受并丢弃任何 Bulk-Out 数据。设备将保持此状态直到复位恢复。


6.6.2 Internal Device Error

内部设备错误

The device may detect an internal error for which it has no reliable means of recovery other than a reset. The device shall respond to such conditions by:
设备可能会检测到内部错误,除了复位之外没有可靠的恢复方法。设备应通过以下方式响应这些条件:

either STALLing any data transfer in progress and returning a Phase Error status (bCSWStatus = 02h).
要么停止任何正在进行的数据传输,并返回阶段错误状态(bCSWStatus = 02h)。
or STALLing all further requests on the Bulk-In and the Bulk-Out pipes until a Reset Recovery.
或停止 Bulk-In 和 BulkOut 管道上的所有进一步请求,直到重置恢复。


6.6.3 Host/Device Disagreements

主机/设备不一致

After recognizing that a CBW is valid and meaningful, and in the absence of internal errors, the device may detect a condition where it cannot meet the host’s expectation for data transfer, as indicated by the Direction bit of the bmCBWFlags field and the dCBWDataTransferLength field of the CBW.
在识别到一个CBW是有效和有意义的,并且没有内部错误的情况下,设备可能会检测到一个条件,即它不能满足主机对数据传输的期望,由 CBW 的 bmCBWFlags 字段的 Direction 位和 dCBWDataTransferLength 字段指示。

In some of these cases, the device may require a reset to recover. In these cases, the device shall return Phase Error status (bCSWStatus = 02h). Details on which cases result in Phase Error vs. non-Phase Error status are given in 6.7 The Thirteen Cases.
在某些情况下,设备可能需要重置才能恢复。在这种情况下,设备应返回Phase Error status (bCSWStatus = 02h)。关于导致相位错误和非相位错误状态的详细情况,请参见 6.7 十三种情况。


6.6.4 Command Failure

命令失败

After recognizing that a CBW is valid and meaningful, the device may still fail in its attempt to satisfy the command. The device shall report this condition by returning a Command Failed status (bCSWStatus = 01h).
在认识到CBW有效且有意义后,设备仍可能无法满足命令。设备应通过返回命令失败状态 (bCSWStatus = 01h) 来报告此情况


6.7 The Thirteen Cases

十三个案例

This section describes the thirteen possible cases of host expectations and device intent in the absence of overriding error conditions. Table 6.1 – Host/Device Data Transfer Matrix graphically displays these thirteen cases.
本节描述在没有覆盖错误条件的情况下,主机期望和设备意图的13种可能情况。表6.1 -主机/设备数据传输矩阵图形显示了这十三种情况。

Important notes about the thirteen cases.
关于这 13 个案例的重要说明。

• Cases (1), (6) and (12) represent the majority of host and device transactions. They indicate those conditions where the host and device agree as to the direction and amount of data to be transferred. These cases are also referred to as “the thin diagonal.”
•案例(1)、(6) 和 (12) 代表了大多数主机和设备事务。它们表示主机和设备就要传输的数据的方向和数量达成一致的条件。这些情况也被称为“薄对角线”。
• Any host or device behavior not specifically outlined in the following sections shall be considered outside this specification and the results are indeterminate.
以下各节中未明确概述的任何主机或设备行为均应被视为本规范之外,并且结果不确定。

USB Bulk-Only Transport 批量传输协议规范_第16张图片


6.7.1 Hn - Host expects no data transfers

Hn - 主机不希望进行数据传输

Cases:
(1) Hn = Dn
(2) Hn < Di
(3) Hn < Do


These cases occur when dCBWDataTransferLength is zero. This indicates that the host is not expecting to send or receive any data to or from the device.
当 dCBWDataTransferLength 为零时,会发生这些情况。这表示主机不希望向设备发送或从设备接收任何数据。


The general requirements of these cases are:
这些情况的一般要求是:
• The value of the Direction bit shall not influence the results of these cases.
方向位的值不应影响这些情况的结果。


The specific host requirements are:
主机的具体要求如下:

  1. The host shall send a valid and meaningful CBW.
    主机应发送有效且有意义的 CBW。
    • The host may set or clear the Direction bit.
    • 主机可以设置或清除 Direction bit。

  2. The host shall attempt to receive a CSW.
    主机应尝试接收CSW。

  3. On a STALL condition receiving the CSW, then:
    在 STALL 条件下接收到 CSW ,则:

    The host shall clear the Bulk-In pipe.
    主机应清除 Bulk-In 管道。
    The host shall attempt to receive the CSW again.
    主机应再次尝试接收 CSW。
    
  4. When the CSW is valid and meaningful, then:
    当 CSW 有效且有意义时,则:
    • [Case (1) ]

    The bCSWStatus = 00h or 01h, and the dCSWDataResidue is 0.
    bCSWStatus = 00h 或 01h,dCSWDataResidual 为 0。
    

    • [Case (2) or (3)]
    If bCSWStatus = 02h, then:
    如果 bCSWStatus = 02h,则:

    The host shall Ignore the value of the dCSWDataResidue.
    主机将忽略 dCSWDataResidue 的值。
    The host shall Perform a Reset Recovery.
    主机需要进行复位恢复。
    

The specific device requirements are:
具体的设备要求是:

  1. The device shall receive a CBW.
    设备应接受 CBW。

  2. When the CBW is valid and meaningful, then:
    当 CBW 有效且有意义时,则:

    • The device shall attempt the command.
    设备应尝试该命令。

    • [Case (1) ]
    If the device had no data to send or receive, then:
    如果设备没有要发送或接收的数据,则:

    The device shall set bCSWStatus to 00h or 01h.
    设备应将 bCSWStatus 设置为 00h 或 01h。
    The device shall set the dCSWDataResidue to 0.
    设备应将 dCSWDataResidue 设置为 0。
    

    • [ Case (2) or (3) ]
    If the device did have data to send or receive, then:
    如果设备确实有要发送或接收的数据,则:

    The device shall set bCSWStatus to 02h.
    设备应将 bCSWStatus 设置为 02h。
    
  3. The device shall return a valid and meaningful CSW.
    设备应返回有效且有意义的 CSW。
    • The device may STALL the Bulk-In pipe if bCSWStatus is not 00h or 01h.
    如果 bCSWStatus 不是 00h 或 01h,设备可能会使 Bulk-In 管道停止。


6.7.2 Hi - Host expects to receive data from the device

Hi - 主机期望从设备接收数据

Cases:
(4) Hi > Dn
(5) Hi > Di
(6) Hi = Di
(7) Hi < Di
(8) Hi <> Do


These cases occur when dCBWDataTransferLength is non zero and the Direction bit is 1 (Data-In). This indicates that the host is expecting to receive data from the device.
当 dCBWDataTransferLength 为非零且 Direction 位为1(数据输入)时,会出现这些情况。这表示主机正在等待从设备接收数据。


The specific host requirements are:
具体的主机要求是:

  1. The host shall send a valid and meaningful CBW.
    主机应发送有效且有意义的 CBW。

  2. The host shall attempt to receive data from the device.
    主机应尝试从设备接收数据。

  3. On a STALL condition receiving data, then:
    在 STALL 条件下接收数据,则:

    • The host shall accept the data received.
    主机应接受接收到的数据。
    • The host shall clear the Bulk-In pipe.
    主机应清除 Bulk-In 管道。

  4. The host shall attempt to receive a CSW.
    主机应尝试接收 CSW。

  5. On a STALL condition receiving the CSW, then:
    在 STALL 条件下接收到 CSW ,则:

    • The host shall clear the Bulk-In pipe.
    主机应清除 Bulk-In 管道。
    • The host shall again attempt to receive the CSW.
    主机应再次尝试接收 CSW。

  6. When the CSW is valid and meaningful, then:
    当 CSW 有效且有意义时,则:

    • [Case (4), (5) , or (6) ]
    If bCSWStatus = 00h or 01h, then:
    如果 bCSWStatus = 00h 或 01h,则:

    The host shall determine the amount of relevant data received from the difference between dCBWDataTransferLength and the value of dCSWDataResidue.
    主机应根据 dCBWDataTransferLength 与 dCSWDataResidue 值之间的差值确定接收到的相关数据量。
    

    • [Case (7) or (8) ]
    If bCSWStatus = 02h, then:
    如果 bCSWStatus = 02h,则:

    The host shall ignore the value of the dCSWDataResidue.
    主机将忽略dCSWDataResidue 的值。
    The host shall perform a Reset Recovery.
    主机将执行复位恢复。
    

The specific device requirements are:
具体设备要求如下:

  1. The device shall receive a CBW.
    设备应接受 CBW。

  2. When the CBW is valid and meaningful, then:
    当 CBW 有效且有意义时,则:

    • The device shall attempt the command.
    设备应尝试该命令。

    • [Case (6) ]
    If the device intends to send dCBWDataTransferLength, then:
    如果设备打算发送 dCBWDataTransferLength,那么:

    The device shall send dCBWDataTransferLength bytes of data.
    设备应发送 dCBWDataTransferLength 字节的数据。
    The device shall set bCSWStatus to 00h or 01h.
    设备应将 bCSWStatus 设置为 00h 或 01h。
    The device shall set dCSWDataResidue to zero.
    设备应将 dCSWDataResidue 设置为零。
    

    • [Case (4) or (5) ]
    If the device intends to send less data than the host indicated, then:
    如果设备发送的数据少于主机指示的数据,则:

    The device shall send the intended data.
    设备应发送预期的数据。

    The device may send fill data to pad up to a total of dCBWDataTransferLength.
    该设备可以发送填充数据以填充总计dCBWDataTransferLength。
    If the device actually transfers less data than the host indicated, then:
    如果设备实际传输的数据少于主机指示的数据,则:

    The device may end the transfer with a short packet.
    设备可能以一个短数据包结束传输。
    The device shall STALL the Bulk-In pipe.
    该装置应 STALL  Bulk-In 管道。
    

    The device shall set bCSWStatus to 00h or 01h.
    设备需要将 bCSWStatus 设置为 00h 或 01h。

    The device shall set dCSWDataResidue to the difference between dCBWDataTransferLength and the actual amount of relevant data sent.
    设备应将 dCSWDataResidue 设置为 dCBWDataTransferLength 与发送的相关数据的实际数量之间的差值。

    • [Case (7) or (8) ]
    If the device either intends to send more data than the host indicated or intends to receive data from the host, then:
    如果设备打算发送比主机指示的数据更多的数据,或者打算从主机接收数据,则:

    The device may send data up to a total of dCBWDataTransferLength.
    设备可以发送最多 dCBWDataTransferLength 的数据。

    If the device actually transfers less data than the host indicated, then:
    如果设备实际传输的数据少于主机指示的数据,则:

    The device may end the transfer with a short packet.
    设备可能以一个短数据包结束传输。
    The device shall STALL the Bulk-In pipe.
    该装置应 STALL Bulk-In 管道。
    

    If the device actually transfers dCBWDataTransferLength then:
    如果设备实际传输 dCBWDataTransferLength,则:
    The device may STALL the Bulk-In pipe.
    设备可能 STALL Bulk-In 管道。

    The device shall set bCSWStatus to 02h.
    设备需要将 bCSWStatus 设置为 02h。


英文资料链接

你可能感兴趣的:(usb,协议,USB,bulk,transport)