07.06.2013 Views

Scsi - Index of

Scsi - Index of

Scsi - Index of

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

90 * @wValue: matches the USB wValue field (le16 byte order)<br />

91 * @w<strong>Index</strong>: matches the USB w<strong>Index</strong> field (le16 byte order)<br />

92 * @wLength: matches the USB wLength field (le16 byte order)<br />

93 *<br />

94 * This structure is used to send control requests to a USB device. It matches<br />

95 * the different fields <strong>of</strong> the USB 2.0 Spec section 9.3, table 9-2. See the<br />

96 * USB spec for a fuller description <strong>of</strong> the different fields, and what they are<br />

97 * used for.<br />

98 *<br />

99 * Note that the driver for any interface can issue control requests.<br />

100 * For most devices, interfaces don't coordinate with each other, so<br />

101 * such requests may be made at any time.<br />

102 */<br />

103 struct usb_ctrlrequest {<br />

104 __u8 bRequestType;<br />

105 __u8 bRequest;<br />

106 __le16 wValue;<br />

107 __le16 w<strong>Index</strong>;<br />

77<br />

108 __le16 wLength;<br />

109 } __attribute__ ((packed));<br />

不过需要说明一点,在usb spec 中,不叫cr,而叫setup packet,在struct urb 里边就有这么一个名字<br />

一样的成员,<br />

799 unsigned char *setup_packet; /* (in) setup packet (control only) */<br />

因为在Linux 中usb 的世界里一个通用的数据结构是urb,很多函数都是以urb 为参数的,所以稍后我们<br />

实际上还是会让urb 中的setup_packet 指针指向这个usb_ctrlrequest 结构体的.毕竟我们最终要提交<br />

的就是urb,而不是cr.并且cr 只是出现在控制传输,而urb 却是四大传输都要用到的.<br />

Ok,在usb mass storage bulk only transport 协议里面,规定的很清楚,要发送GET MAX LUN 请求,<br />

必须把bmRequestType 设置为device to host,class,interface,同时把bRequest 设置为254(FEh),<br />

即咱们这里的0xfe,而wValue 设置为0,w<strong>Index</strong> 设置为接口的编号,最后wLength 设置为1.<br />

需要解释一下,什么叫bmRequestType 设置device to host,class,interface?实际上,usb 2.0 规范<br />

里面指出,所有的usb 设备都会响应主机的一些请求,这些请求必须来自主机,通过设备的默认控制管道发<br />

出.(即0 号端点所对应的那个管道)这些请求,或者说这些request,是通过控制传输来实现的,请求以及请<br />

求所需的参数都是通过setup packet 来发送的.主机负责建立好这个setup packet.(也就是咱们刚才的<br />

那个cr,后来的setup_packet.)每个setup packet 包含8 个bytes.她们的含义如下:<br />

byte0: bmRequestType,注意,在刚才咱们代码中数据结构struct ctrlrequest 里边是写的<br />

bRequestType,但是她们对应的是相同的冬冬.而之所以usb 协议里写成bmRequestType,是因为她实<br />

际上又是一个位图(m 表示map),也就是说,尽管她只有1 个byte,但是她仍然是当作8 位来用.她的8 位<br />

的含义是:<br />

D7: 控制传输数据传输的方向,0 表示方向为主机到设备,1 表示方向为设备到主机.(有时控制传<br />

输除了发命令阶段以外,可能还有数据传输阶段,此处表示的是在数据传输那个阶段的传输方向.)<br />

D6...5: 请求的类型,0 称为标准类型(Standard),1 称为Class,2 称为Vendor,3 则是保留的,<br />

不能使用.<br />

D4...0: 接收者,0 表示设备,1 表示接口,2 表示端点,3 表示其它,4...31 都是保留的,不能使用.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!