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.

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.

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.

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.

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).
or STALLing all further requests on the Bulk-In and the Bulk-Out pipes until a Reset Recovery.

6.6.3 Host/Device Disagreements

After recognizing that a CBW is valid and meaningful, ( != 6.6.1 CBW Not Valid )
and in the absence of internal errors, ( != 6.6.2 Internal Device Error )

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.

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.

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).

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.

Important notes about the thirteen cases.

· 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.”

· Any host or device behavior not specifically outlined in the following sections 
shall be considered outside this specification and the results are indeterminate.

6.7.1 Hn - Host expects no data transfers : Case (1), (2), (3)

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.

The specific host requirements are:

1. The host shall send a valid and meaningful CBW.
2. The host shall attempt to receive a CSW.
3. On a STALL condition receiving the CSW, then:
( 6.6.1 CBW Not Valid ) or ( 6.6.2 Internal Device Error )
   · The host shall clear the Bulk-In pipe.
   · The host shall attempt to receive the CSW again.
4. When the CSW is valid and meaningful, then:

· [Case (1)] The bCSWStatus = 00h or 01h, and the dCSWDataResidue is 0.
  ( 6.6.4 Command Failure )
  send next a valid and meaningful CBW.

· [Case (2) or (3)] If bCSWStatus = 02h, then:
  ( 6.6.3 Host/Device Disagreements )

The host shall Ignore the value of the dCSWDataResidue.
The host shall Perform a Reset Recovery.

The specific device requirements are:

1. The device shall receive a CBW.
2. When the CBW is not valid and meaningful ( 6.6.1 CBW Not Valid )
· else 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.
The device shall set the dCSWDataResidue to 0.

· [Case (2) or (3)]   ( 6.6.3 Host/Device Disagreements )
If the device did have data to send or receive, then:
The device shall set bCSWStatus to 02h. ( may STALL the Bulk-In pipe )

3. The device shall return a valid and meaningful CSW.
· The device may STALL the Bulk-In pipe if bCSWStatus is not 00h or 01h.

6.7.2 Hi - Host expects to receive data from the device : Case 4, 5, ,6, 7, 8

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.

The specific host requirements are:

1. The host shall send a valid and meaningful CBW.

2. The host shall attempt to receive data from the device.
3. On a STALL condition receiving data, then: ( data xfer end, Hi != Di )
   The host shall accept the data received.
   The host shall clear the Bulk-In pipe. ( to receive a CSW )

4. The host shall attempt to receive a CSW.
5. On a STALL condition receiving the CSW, then:
   The host shall clear the Bulk-In pipe.
   The host shall again attempt to receive the CSW.

6. When the CSW is valid and meaningful, then:

· [Case (4), (5), or (6)]
If bCSWStatus = 00h or 01h, then:
The host shall determine the amount of relevant data received
from the difference between dCBWDataTransferLength
and the value of dCSWDataResidue.

· [Case (7) or (8)]
If bCSWStatus = 02h, then:
The host shall ignore the value of the dCSWDataResidue.
The host shall perform a Reset Recovery.

The specific device requirements are:

1. The device shall receive a CBW.
2. When the CBW is valid and meaningful, then:
· The device shall attempt the command.

· [Case (6)]
If the device intends to send dCBWDataTransferLength, then:
The device shall send dCBWDataTransferLength bytes of data.
The device shall set bCSWStatus to 00h or 01h.
The device shall set dCSWDataResidue to zero.

· [Case (4) or (5) ] Hi > Dn, Hi > Di
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.

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.
The device shall set bCSWStatus to 00h or 01h.
The device shall set dCSWDataResidue to the difference
between dCBWDataTransferLength and the actual amount of relevant data sent.

· [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.
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.

If the device actually transfers dCBWDataTransferLength then:
The device may STALL the Bulk-In pipe.
The device shall set bCSWStatus to 02h.
3. The device shall return a valid and meaningful CSW.

6.7.3 Ho - Host expects to send data to the device, Case 9, 10, 11, 12, 13

These cases occur when dCBWDataTransferLength is non zero
and the Direction bit is 0 (Data-Out).
This indicates that the host is expecting to send data to the device.

The general requirement of these cases is:

· The host shall not send zero length packets.

The specific host requirements are:

1. The host shall send a valid and meaningful CBW.
2. The host shall send data to the device.
· The host shall send a short packet only at the end of the data transfer.

3. On a STALL condition sending data, then: ( Ho > Do ), ( Ho > Dn )
· The host shall clear the Bulk-Out pipe.

4. The host shall attempt to receive a CSW.
5. On a STALL condition receiving the CSW, then:
· The host shall clear the Bulk-In pipe.
· The host shall again attempt to receive the CSW.

6. When the CSW is valid and meaningful, then:

· [Case (9), (11), or (12)]
If bCSWStatus = 00h or 01h, then:
The host shall determine the amount of data
that was processed from the difference of
dCBWDataTransferLength and the value of dCSWDataResidue.

· [Case (10) or (13)]
If bCSWStatus = 02h, then:
The host shall ignore the value of the dCSWDataResidue.
The host shall perform a Reset Recovery.

The specific device requirements are:

1. The device shall receive a CBW.
2. When the CBW is valid and meaningful, then:
· The device shall attempt the command.

· [Case (9), (11), or (12)]
If the device intends to process less than or
equal to the amount of data that the host indicated, then:
The device shall receive the intended data.
The device shall either accept a total of dCBWDataTransferLength, (Ho = Do)
or end the transfer prematurely by STALLing the Bulk-Out pipe. (Ho > Do), (Ho > Dn)

The device shall set bCSWStatus to 00h or 01h.
The device shall set dCSWDataResidue to the difference
between dCBWDataTransferLength and the actual amount of data
that was processed by the device.

· [Case (10) or (13)]  (Ho <> Di), (Ho < Do)
If the device either intends to process more data than the host indicated
or intends to send data, then:

The device may receive data up to a total of dCBWDataTransferLength.
The device shall either accept a total of dCBWDataTransferLength,
or end the transfer prematurely by STALLing the Bulk-Out pipe.
The device shall set bCSWStatus to 02h.

3. The device shall return a valid and meaningful CSW.
· The device may STALL the Bulk-In pipe if bCSWStatus is not 00h or 01h.

USB Mass Storage Class – Bulk Only Transport - Error Handling的更多相关文章

  1. USB Mass Storage大容量存储的基本知识

    http://www.crifan.com/files/doc/docbook/usb_disk_driver/release/htmls/ch02_msc_basic.html 目录 2.1. US ...

  2. USB Mass Storage学习笔记-STM32+FLASH实现U盘

    一.内容概述  采用STM32内部自带USB控制器外加大页NAND FLASH K9F1G08U0A实现一个128M的U盘. 1.STM32的USB控制器 STM32F103的MCU自带USB从控制器 ...

  3. USB Mass Storage协议分析

    目录 简介 指令数据和状态协议 CBW指令格式 CSWCommand Status Wrapper状态格式 SCSI命令集 Format Unit Inquiry MODE SELECT 简介 USB ...

  4. USB mass storage协议

    这一节主要把在实现“linux模拟U盘功能”过程中的一些调试过程记录下来,并加以解析. 一.背景知识     1.USB Mass Storage类规范概述        USB 组织在univers ...

  5. 实现Linux下的U盘(USB Mass Storage)驱动

    如何实现Linux下的U盘(USB Mass Storage)驱动 版本:v0.7 How to Write Linux USB MSC (Mass Storage Class) Driver Cri ...

  6. 如何实现Linux下的U盘(USB Mass Storage)驱动

    如何实现Linux下的U盘(USB Mass Storage)驱动 版本:v0.7 How to Write Linux USB MSC (Mass Storage Class) Driver Cri ...

  7. USB Mass Storage大容量存储 The Thirteen Class章节的理解

    http://blog.csdn.net/xgbing/article/details/7002558 USB Mass Storage 6.7 The Thirteen Class章节的理解 Cas ...

  8. Android USB Connections Explained: MTP, PTP, and USB Mass Storage

    Android USB Connections Explained: MTP, PTP, and USB Mass Storage Older Android devices support USB ...

  9. usb mass storage device

    Problem adding USB host device to KVM Windows guest machine. Status: CLOSED CURRENTRELEASE   Aliases ...

随机推荐

  1. python网络编程-Select\Poll\Epoll异步IO

    首先列一下,sellect.poll.epoll三者的区别 select select最早于1983年出现在4.2BSD中,它通过一个select()系统调用来监视多个文件描述符的数组,当select ...

  2. eclipse各种报错

    1.控制台报这个错是由于tomcat的session缓存的问题; org.apache.catalina.session.StandardManager doLoad 造成原因:上次未正确关闭tomc ...

  3. 洛谷P2746校园网

    传送门啦 下面来看任务B.我们发现,图中只要存在入度为0的点和出度为0的点就永远不可能满足要求:" 不论我们给哪个学校发送新软件,它都会到达其余所有的学校 ".我们还发现,只要在入 ...

  4. Linux基础 - tmux

    安装 yum install tmux 类似vim当中存在命令行模式以及编辑模式,从编辑模式进入命令行模式需要先按ESC键,在tmux当中进行操作也要先准备好"姿势"再操作,默认情 ...

  5. C#基础系列 - 抽象类及其方法的学习

    在C#中使用关键字 abstract 来定义抽象类和抽象方法. 不能初始化的类被叫做抽象类,它们只提供部分实现,但是另一个类可以继承它并且能创建它们的实例. "一个包含一个或多个纯虚函数的类 ...

  6. 【LOJ】#2290. 「THUWC 2017」随机二分图

    题解 看了一眼觉得是求出图对图统计完美匹配的个数(可能之前做过这样模拟题弃疗了,一直心怀恐惧... 然后说是统计一下每种匹配出现的概率,也就是,当前左边点匹配状态为S,右边点匹配状态为T,每种匹配出现 ...

  7. 【LOJ】#2306. 「NOI2017」蔬菜

    题解 从后往前递推 如果我们知道了第i天的最优方案和第i天选择的蔬菜,加入第i天选择的蔬菜数量为S,我们只需要减去最小的S - (i - 1) * M 个蔬菜即可 所以我们只要求出最后一天的蔬菜选择 ...

  8. Ionic Js二:背景层

    我们经常需要在 UI 上,例如在弹出框.加载框.其他弹出层中显示或隐藏背景层. 在组件中可以使用\(ionicBackdrop.retain()来显示背景层,使用\)ionicBackdrop.rel ...

  9. ref:CodeIgniter框架内核设计缺陷可能导致任意代码执行

    ref:https://www.seebug.org/vuldb/ssvid-96217 简要描述: 为准备乌云深圳沙龙,准备几个0day做案例. 官方承认这个问题,说明会发布补丁,但不愿承认这是个『 ...

  10. CSUOJ 1224 ACM小组的古怪象棋

    Description ACM小组的Samsara和Staginner对中国象棋特别感兴趣,尤其对马(可能是因为这个棋子的走法比较多吧)的使用进行深入研究.今天他们又在 构思一个古怪的棋局:假如Sam ...