E-Engineer Business card--ufi COMMAND,USB drive letter Display

Source: Internet
Author: User

USB Mass Storage Class Specification Overview
The USB Mass storage device protocol, the mass storage protocol, is suitable for large capacity storage devices such as hard disks and USB drives. The interface endpoints used by the protocol have Bulkin, Bulkout, and interrupt endpoints. The device class also contains 6 separate subclasses and 3 transport protocols.


The BULK-ONLY transport specification uses only the BULK endpoint to transmit data/commands/states, while the CBI transport specification uses control/bulk/interrupt three types of endpoints for data/command/State delivery.
The USB stick in our hands is in accordance with the SCSI protocol. To know that a USB flash drive is not only a device, it is also a storage device, similar to a hard disk, the USB protocol itself does not define instructions for the operation of the storage device, so it is necessary to complete the read and write operation via SCSI.

Support for the Mass Storage protocol is available in Microsoft Windows, so USB mobile devices only need to follow the Mass Storage protocol to organize data and process commands, enabling exchange of data with the PC. The Flash storage unit form of FAT16 file system, so that you can directly in the Windows browser through the removable disk to Exchange data, Windows is responsible for the FAT16 file system management, USB devices do not need to intervene FAT16 Specific details of the file system operation.

USB Massstorage device (with a yellow exclamation mark) will be displayed on Devices manager after a successful enumeration, otherwise the Unknow device will be displayed.

Instead, the host displays the drive letter only after the UFI (specifically after the Inquiry command), and the yellow exclamation point on the USB Massstorage device that was originally in Devices manager disappears.

Because this time the USB device has been enumerated successfully (the host sends the GetDescriptor, setaddress and so on the request all replies successfully can be correctly enumerated), so can through the bushound to see in the USB UFI command situation, The enumeration of USB devices is implemented through the endpoint, while the USB UFI command is implemented through the endpoint, and all of the command's data flows are at Endpoint 1. In addition to Bushound, there are many software to view the USB bus data, such as USB view, the software to view Flash data is winhex.

Enumeration process CATC instrument Fetch data file: http://download.csdn.net/detail/luckywang1103/6315437 Usbufi.usb

1, Getmaxlun (0xFE)

1) Setup Stage

2) Data Stage

3) Status Stage

The program corresponding to this stage is

 Case Getmaxlun:         // in fact, for a USB flash drive, ignoring this        step has no effect // requires the device to return a byte to the host to indicate how many        USB devices // logical device, the data returned is the maximum device logic number (0 to         // If 2 is returned, it represents 0, 1, 23 logical devices        Sfr_write (FIFO0,0x00);        Sfr_write (E0CSR,0x0a); break;

Next, start the UFI command transfer at endpoint 1.

UFI command constitutes the following:cbw-> data->CSW, three stages

Cbw:command Block Wrapper Command block packet

Csw:command Status Wrapper command execution state

2. Inquiry Command (0x12)

1) CBW

The DATA0 data of the UFI command issued by the host at Endpoint 1 can be parsed against the Figure Table 5.1.

DCBWSIGNATURE:55 identify this data packet as CBW

dcbwtag:90 C8 E8 Command Block Tag send by host

dcbwdatatransferlength:24 XX data numbers that host expect to transfer on the bulk-in or bulk-out endpoint

The remaining bytes is cbwcb:12 00 00 00 24 00 00 00 00 00 00 00

CBWCB (command block inside CBW) 12 byte parsing reference "USB Mass Storage class-ufi Command Specification"

12:inquiry Command

24:allocation Length Specifies the maximum number of bytes of inquiry data to be returned, data phase Max Transfer bytes

2) Data in

This bytes is returned in accordance with the format requirements of inquiry data, the analysis of the specific protocol is referred to "USB Mass Storage class-ufi Command Specification"

3) CSW

DCSWSIGNATURE:55 identify this data packet as CSW

dcswtag:90 C8 EB CSW This field is the same as the Dcbwtag field of CBW

3, read_format_capacity (0x23)

1) CBW

2) Data

3) CSW

4, read_capacity (0x25)

1) CBW

2) Data

3) CSW

5, Read_10 (0x28)

If all of the above requests are returned correctly, host will issue the DBR data of the 0 cluster 0 sectors of the read file system into the file system recognition phase.

1) CBW

2) Data

3) CSW

6, ModeSense6 (0x1A)

1) CBW

2) Data

3) CSW

7, repeat the 6th step, ModeSense6 (0x1A)

8, repeat the 4th step, read_capacity (0x25)

9, repeat the 4th step, read_capacity (0x25)

10, repeat the 5th step, read_10 (0x28)

11, repeat the 5th step, read_10 (0x28)

12, repeat the 4th step, read_capacity (0x25)

13, repeat the 4th step, read_capacity (0x25)

14, repeat the 5th step, read_10 (0x28)

15. Test Unity Ready (0x00)

1) CBW

3) CSW

16, repeat the 4th step, read_capacity (0x25)

17, repeat the 4th step, read_capacity (0x25)

18, repeat the 4th step, read_capacity (0x25)

19, repeat the 5th step, read_10 (0x28)

20. Test Unity Ready (0x00) is repeated next

Description

MASS the set of SCSI commands used by the storage device

0x00:testunityready
0x03:request Sense

0x12:inquiry

0x1a:modesense6

0x1b:startstop

0x1e:mediumremoval

0x23:readformatcapacity

0x25:readcapacity

0x28:read10

0x2a:write10

0x2f:verify

0x5a:modesense10

The host first issues the inquiry command, and after responding to the inquiry, it can see the drive letter.


The Readformatcapacity command is issued after inquiry, which is the "Factory custom command" in the SCSI specification and can refer to the UFI command set document (actual
, all SCSI command sets used by the USB drive can refer to the UFI documentation, which is more concise than the SCSI standard documentation. Note that this command is not described in the bushound and must be
The "Device" tab will check the USB Mass Storage device node of this USB flash drive to see the data flow of this command.

The Readcapacity command is issued after the readformatcapacity.

Read (10) is sent when the USB drive reads the data (read sector). Readcapacity will send read (10) to read the first sector of the USB flash drive when it is finished.

Write (10) is sent when the USB drive writes data (write sector).

Testunitready will be sent periodically when no other data is transmitted, and if the device does not respond successfully to the CSW to the host, the host considers the device no longer exists. Now if you double-click the disk diagram
Windows prompts "Please insert a disk".

Verify is useful in writing data, which means verifying the data, generally returning to the successful CSW directly. In general, the work of data validation in the receiving and writing data to the media has been done incidentally, if the hair
Now error, then directly tell the host that the data transmission error, will not wait until the host verify. Of course, this is not an inevitable solution.

Requestsense: If CSW indicates that the transmission is unsuccessful, the host makes this request.

Startstop temporarily did not find great use, generally directly return to the successful CSW.

Mediumremoval is useful when the USB flash drive is eject and processing is incorrect windows will pop up an error message.

MODESENSE6/10 these two commands can not be supported (does not support does not mean that no response, any one command you have to react, for unsupported commands, can be through the stall handshake to the host
Show), and I have not encountered any unusual situation, and I have looked at some of the U disk, a considerable part of it is casually back to a few data to the host. These two commands will only be sent once after the USB stick is inserted and no longer be sent
Send.

E-Engineer Business card--ufi COMMAND,USB drive letter Display

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.