The enumeration process of USB mass storage is summarized earlier, and if all enumerations are normal, then the data interchange defined by the BULKONLY protocol is entered, and the SCSI protocol is included in the packet.
Bulkonly Agreement usbmassbulk_10.pdf, search on the internet can be found, in fact, is to say the standard commands and so on, in this document the most need to pay attention to is CBW and CSW.
Cbw:command Block Wrapper, the agreement inside the text description is not much to say, see for yourself,
Dcbwsignature:
Signature that helps identify the this data packet as a CBW. The signature field shall contain the value 43425355h (little endian), indicating a CBW.
Plainly, here is a sign that this is a CBW package.
Dcbwtag:
A Command Block Tag sent by the host. The device shall echo the contents of this field from the host in the Dcswtagfield of the associated CSW. The dcswtagpositively associates a CSW with the corresponding CBW.
The above said very clearly, this is the host issued a tag, this tag in the slave to host the data is also this tag, do not change, the host gave what, we will give him what.
Dcbwdatatransferlength:
Not copy English, too much, this is the host is expected to receive data or sent data, but as slave we do not necessarily host need to send back how much.
Bmcbwflags:
These bits are defined as follows:
Bit 7 defines the direction – if the Dcbwdatatransferlength is 0, then the device ignores this bit, otherwise:
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:
Logical Unit Number (LUN), as we mentioned earlier, FUDAN_ABC also said, a U-disk has only one LUN, of course, in general.
Bcbwcblength:
This defines the valid length of the command block. The only legal values is 1 through (01h through 10h).
Here is command block, and the valid is 1-16. What is this stuff?
The following is the SCSI command, which is the SCSI command, slave is to follow these commands to answer host. That's what we're talking about.
How long is the command for this SCSI?
CBWCB:
The SCSI command block, Bcbwcblength, shows how long this command is.
To cite an example, see if it's right.
25.3 LEN 1f 00 00 00 31 62.1.0
25.3 Do (2e)----------usbcp...$ 62.2.0
00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 ... ... $ ... 62.2.16
25.2 LEN 24 00 00 00 36 63.1.0
25.2 DI------6f-------.... ECos 63.2.0
4d (6f)----Mass Storage 63.2.16
2e 30 31 0.01 63.2.32
25.2 LEN 0d 00 00 00 13 64.1.0
25.2 DI-2e----------usbsp
Know that this packet is a bus hound grabbed the package bar, now look.
25.3 LEN 1f 00 00 00 31 62.1.0
Here 25.3 means that the 25 is the 25th device, 3 is that this is the data entered through the 3 endpoint, the front does define the 3 endpoint as bulk out
Len is 0x1f in length, meaning that host sends 31 bytes to slave.
25.3 Do (2e)----------usbcp...$ 62.2.0
00 00 00 24 00 00 00 00 00 00 00 00 00 00 00 ... ... $ ... 62.2.16
25.3 will not say, from the end 3 sent 31 bytes to slave,do:data out, the rest is the data,
55 53 42 43 Look at Cbwsignature is not very similar, but one is little endian, one is big endian, the size of the end this does not speak.
2e 96 88 Look at Dcbwtag, the previous protocol said this is the host generation, this does not need to pay attention. But this field needs to be backfill in CSW.
24 00 00 00 This is Dcbwdatatransferlength, the next host wants to slave back 36 data. The first command of the SCSI protocol is
Inquiry, inside a 36 byte, just right is not.
80 00 06 12 It contains more things, first of all, Bmcbwflags, whose value is 0x80, where the 7th bit is 1 means that Data-in,host is expecting the data to be sent in.
Bcbwlun its value is 0x00, here is only one LUN, of course, is 0 oh. Bcbwcblength its value is 0x06, which means that here is the next 6 data,
There will be a SCSI command coming over, this command length is 6. In fact, this command is inquiry. The 6 data is 12 00 00 00 24 00, the first one is 0x12 is the Inquiry command defined in the SCSI protocol.
Okay, CBW finally finished, and introduced the SCSI protocol.
As for CSW, let's summarize it.
Dcswsignature: The first data is also a sign, mainly used to show you their identity. 53425355h (little endian).
Dcswtag: This tag is the tag in front of the CBW, the front that directly written in here just fine.
Dcswdataresidue: This field tells the host how much data has not been sent out yet. There is a large amount of time data, so it needs to be sent in batches.
Bcswstatus: This field is to tell the host whether to send the correct, correct or not check the table is good, indicating that 0x00 success.
Well CSW also summed up, I found that summed up not how to deal with the SCSI protocol, next time to summarize SCSI.
USB-CSW Tour