You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
所以,bmRequestType 被设device to host,class,interface,表示,数据传输阶段传输方向是设<br />
备到主机,请求的类型是Class,意思是,请求类型可以有好几种,首先usb spec 本身定义了很多种标准请<br />
求,<br />
所有的usb 设备都必须支持这些标准请求,或者或标准request,另一方面,一类设备或者厂商自己也可以<br />
定<br />
义自己的额外的一些请求,显然这里get max lun 就是usb mass storage 这个类,或者说这个class 所定<br />
义的请求,因此,请求类型设置为class,而request 接收者可以是设备,也可以是接口,还可以是端点,对get<br />
max lun 这个命令来说,她是针对一个u 盘的,所以她的接收者应该是interface.<br />
byte1: bRequest,1 个byte,指定了是哪个请求.每一个请求都有一个编号,咱们这里是GET MAX<br />
LUN,其编号是FEh.<br />
byte2...3: wValue,2 个bytes,不同请求有不同的值,咱们这里刚才已经说了,必须为0.<br />
78<br />
byte4...5: w<strong>Index</strong>,2 个bytes,不同请求有不同的值,咱们这里要求被设置为是interface number.<br />
byte6...7: wLength,2 个bytes,如果接下来有数据传输阶段,则这个值表征了数据传输阶段传输多少<br />
个bytes,没啥好说的,这个值在GET MAX LUN 请求中被规定为1,也就是说返回1 个byte 即可.<br />
结合函数调用的实参和函数的定义,可见,对于这个cr 来说,其bRequest 被赋值为<br />
US_BULK_GET_MAX_LUN,bRequestType 被赋值为<br />
USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE,而wValue 被设为0,w<strong>Index</strong> 被设置<br />
为<br />
us->ifnum, 推开记忆的门,我们发现在associate_dev()函数中,us->ifnum 被赋值为<br />
intf->cur_altsetting->desc.bInterfaceNumber,即她确实对应了interface number. wLength 被<br />
赋<br />
值为1.设置好cr 之后,就可以把她传递给urb 的setup_packet 了.对比上面的<br />
usb_stor_control_msg()<br />
函数中第232 行,和下面函数usb_fill_control_urb()的定义,即可看出urb 的setup_packet 指针指向<br />
了这个cr.具体来看usb_fill_control_urb()函数,这个函数定义于include/linux/usb.h 中:<br />
812 /**<br />
813 * usb_fill_control_urb - initializes a control urb<br />
814 * @urb: pointer to the urb to initialize.<br />
815 * @dev: pointer to the struct usb_device for this urb.<br />
816 * @pipe: the endpoint pipe<br />
817 * @setup_packet: pointer to the setup_packet buffer<br />
818 * @transfer_buffer: pointer to the transfer buffer<br />
819 * @buffer_length: length <strong>of</strong> the transfer buffer<br />
820 * @complete: pointer to the usb_complete_t function<br />
821 * @context: what to set the urb context to.<br />
822 *<br />
823 * Initializes a control urb with the proper information needed to submit<br />
824 * it to a device.<br />
825 */<br />
826 static inline void usb_fill_control_urb (struct urb *urb,<br />
827 struct usb_device *dev,<br />
828 unsigned int pipe,<br />
829 unsigned char *setup_packet,