USB Mass Storage

參見:USB Mass StorageClass Bulk-Only Transport

1 規範概述和範圍

前提條件:熟悉USB協議規範和USB海量存儲類規範概述。

本規範只描述塊傳輸,也就是僅通過塊類型(而不是控制或中斷類型的端點)的端點傳輸命令、數據和狀態。本規範僅使用默認的通道清除塊端點上的STALL條件,發出相關的請求如下。本規範不需要使用中斷端點。

本規範定義了邏輯單元,該邏輯單元都有共同的設備特性。儘管這些特性給類似於海量存儲的設備提供擁有相同的USB接口描述符支持,但是它不能用於實現接口橋接設備。

2術語和縮寫

Command Block Wrapper (CBW)

一個包含一個命令塊和關聯的信息的數據包

Command Status Wrapper (CSW)

一個包含一個命令塊狀態的數據包。

Data-In

從設備到主機的數據傳輸。

Data-Out

從主機到設備的數據傳輸。

Device Request

使用默認通道傳輸的從主機到設備的請求。

Phase Error

從設備返回的處理結果,在設備復位之前,後續的CBW是不確定的。

Processed

接收到數據,而且設備到主機端點的內部控制不再需要考慮。

Relevant

發送到主機的數據是有意義的。

Reset Recovery

一個錯誤恢復過程,主機可以給設備準備好下一個CBW。

3功能特點

3.1 Bulk-Only Mass Storage Reset (class-specificrequest)

該請求是復位海量存儲設備和其相關的接口。

這個類-相關請求可以準備好設備,用於主機的下一個CBW傳輸。

主機使用默認通道發送該請求到設備。設備需要維護塊數據的toggle比特和端點STALL條件(BOT復位也需要保持)。在復位完成之前,設備返回設備的狀態爲NAK。

在默認通道上發送塊存儲設備復位請求前,主機需要發送如下的請求道默認通道:

· 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

3.2 Get Max LUN (class-specific request)

設備可能實現了幾個共享設備特性的邏輯單元。主機使用bCBWLUN域來指示CBW的目標是設備的第幾個邏輯單元。Get MaxLUN設備請求是確定設備所支持的邏輯單元數。設備上的邏輯單元數應該是從LUN 0到最大LUN 15(Fh)連續的。發送一個Get MaxLUN設備請求,主機需要發送如下的命令到默認通道。

· 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

設備返回一個字節的數據來包含設備所支持的最大LUN數。比如說,如果設備支持4個LUN,LUN從0 到3,返回值是3。如果設備沒有LUN,返回值是0。主機不能發送CBW到一個不存在的LUN。     

在不支持多LUN的設備上發送Get MaxLUN請求,可能返回STALL。

3.3主機/設備數據包傳輸順序

主機在讀(DATA-IN)或寫(DATA-OUT)數據前,必須先發送CBW,CSW命令在最後。主機需要在發送CBW前,發送數據讀或CSW命令。過程:CBW à DATA IN/ DATAOUTàCSW。

如果dCBWDataTransferLength爲0,設備和主機在CBW和CSW之間沒有數據傳輸。

3.4 命令隊列

主機在收到上一個CBW的CSW之前,不能發送CBW。如果主機連續發送了兩個CBW,期間沒有CSW或復位。設備響應第二個CBW是不確定的。

3.5 雙向命令協議

在一個單獨的命令中,該規範不支持雙向數據傳輸。

4 標準描述符

設備支持如下幾種標準USB描述符:

設備: 每個USB設備擁有一個設備描述符.

配置: 每個USB設備含有一個默認的配置描述符,該配置描述符至少支持一個接口.

接口: 設備支持至少一個接口,這裏指海量數據接口. 有些設備支持其他的接口,提供其他的能力.

端點: 海量存儲設備支持如下的端點,默認通道在所有的設備上都需要支持。

   Bulk-In端點。

   Bulk-Out端點。

   其他類型的設備可能支持另外的端點,提供其他功能。主機使用第一個接口的Bulk-In和Bulk-Out端點。

字符串:設備支持唯一的串口數。

標準描述符的更詳細的信息參考USB協議規範第9章,USB設備框架。

4.1 設備描述符

Table 4.1 - Device Descriptor



4.2 配置描述符

Table 4.2 - Configure Descriptor


4.3 接口描述符

        每個設備至少含有一個接口描述符。海量存儲設備只有一個接口描述符,該描述符的介紹如表4-3所示。

Table 4.3 - Bulk-Only DataInterface Descriptor




 

4.3 端點描述符

海量傳輸的數據接口含有3個端點,分別是默認端點、讀取CSW狀態或數據的Bulk-In端點和發送CBW或數據的Bulk-Out端點。其中默認端點對於所有的設備都一樣,海量存儲的Bulk-In和Bulk-Out 端點描述符的介紹分別如表4-4和4-5所示。

Table 4.4 –Bulk-In EndpointDescriptor 



Table 4.5 - Bulk-Out EndpointDescriptor



 

5 命令/數據/狀態協議

        圖1介紹了命令、數據和狀態傳輸的數據流程。



 

Figure 1 - Command/Data/Status Flow

5.1 命令塊包(CBW)

        每個CBW通過Bulk-Out端點進行傳輸,每個CBW的長度是31字節。CBW的傳輸是小端格式。CBW個字節的定義如表5.1所示。

Table 5.1 - Command Block Wrapper



 

    dCBWSignature:0x43425355

   dCBWTag:

dCBWDataTransferLength:主機期望傳輸的數據長度。

bmCBWFlags: 主要定義數據的傳輸方向,由bit7定義(0–out,1-in),其他比特默認爲0。

bCBWLUN: 邏輯單元號。

bCBWCBLength:CB的有效長度。

CBWCB:設備執行的命令塊,這裏是SCSI命令,一般是16字節。

 

5.2 命令傳輸狀態包(CSW)

        CSW用Bulk-In端點進行傳輸,其長度是13字節,用於表示CBW傳輸的狀態。

Table 5.2 - Command Status Wrapper



 

dCSWSignature:0x53425355

dCSWTag:

dCSWDataResidue:

bCSWStatus: CBW傳輸的成功或失敗狀態。爲0表示傳輸成功,非0表示傳輸失敗。如表5.3所示。

Table 5.3 - Command Block StatusValues 

 

5.3 數據傳輸條件

        本節描述主機和設備如何保持同步。主機使用CBW的方向和長度域(dCBWDataTransferLength)進行傳輸。設備確定實際的傳輸方向和長度。設備用合適的CSW返回CBW的結果。


Figure 2 - Status Transport Flow

命令傳輸

主機通過Bulk-Out端點發送CBW到設備,每個CBW中包含一個命令塊。正確傳輸情況下,設備使用ACK回覆主機,在命令傳輸期間如果主機檢測到STALL,主機需要執行復位恢復。

數據傳輸

主機根據方向決定發送或接收dCBWDataTransferLength長度的數據。在數據傳輸完成或報告錯誤之前,設備可能以STALL 端點的方式結束命令。

狀態傳輸

CSW返回CBW傳輸的狀態,通過Bulk-IN端點進行傳輸。CSW的長度爲13字節。

復位恢復(Reset Recovery)

復位恢復,主機需要發送如下的命令:

(a) a Bulk-Only Mass Storage Reset

(b) a Clear Feature HALT to the Bulk-Inendpoint

(c) a Clear Feature HALT to the Bulk-Outendpoint

6 主機/設備數據傳輸

6.1 有效和有意義的CBW

6.2.1 Valid CBW

The device shall consider the CBW validwhen:

· The CBW was received after the device had sent aCSW or after a reset,

· the CBW is 31 (1Fh) bytes in length,

· and the dCBWSignature is equal to43425355h.

6.2.2 Meaningful CBW

The device shall consider the contents of a validCBW meaningful when:

· no reserved bits are set,

· the bCBWLUN contains a valid LUN supportedby the device,

· and both bCBWCBLength and the content ofthe CBWCB are in accordance with

bInterfaceSubClass.

6.2 有效和有意義的CSW

6.3.1 Valid CSW

The host shall consider the CSW validwhen:

· the CSW is 13 (Dh) bytes in length,

· and the dCSWSignature is equal to53425355h,

· the dCSWTag matches the dCBWTag fromthe corresponding CBW.

6.3.2 Meaningful CSW

The host shall consider the contents of the CSWmeaningful when:

either the bCSWStatus value is 00h or 01hand the dCSWDataResidue is less than or equal to

dCBWDataTransferLength..

or the bCSWStatus value is 02h.

6.3錯誤處理

    設備對於主機的請求,在不能滿足的情況下,返回STALL錯誤。

主機收到CSW是無效或無意義的,使用復位恢復。

6.4 錯誤類型

In every transaction between the host and thedevice, there are four possible classes of errors. These classesare not always independent of each other and may occur at any timeduring the transaction.

6.4.1 無效CBW

If the CBW is not valid, the device shall STALLthe Bulk-In pipe. Also, the device shall either STALL the Bulk-Outpipe, or the device shall accept and discard any Bulk-Out data. Thedevice shall maintain this state until a Reset Recovery.

6.4.2 設備內部錯誤

The device may detect an internal error for whichit has no reliable means of recovery other than a reset. The deviceshall respond to such conditions by: either STALLing any datatransfer in progress and returning a Phase Error status (bCSWStatus = 02h).

or STALLing all further requests on the Bulk-Inand the Bulk-Out pipes until a Reset Recovery.

6.4.3 Host/DeviceDisagreements

After recognizing that a CBW is valid andmeaningful, and in the absence of internal errors, the device maydetect a condition where it cannot meet the host’s expectation fordata transfer, as indicated by theDirection bit of thebmCBWFlags field and the dCBWDataTransferLength fieldof the CBW. In some of these cases, the device may require a resetto recover. In these cases, the device shall return Phase Errorstatus (bCSWStatus =02h). Details on which cases result inPhase Error vs. non-Phase Error status are given in 6.7 TheThirteen Cases.

6.4.4 命令失敗

After recognizing that a CBW is valid andmeaningful, the device may still fail in its attempt to satisfy thecommand. The device shall report this condition by returning aCommand Failed status (bCSWStatus = 01h).

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章