我在使用嵌入式控制器作为主机与USB读卡器通信时遇到了困难。凭借极大的耐心,我已经能够发送控制事务并操纵LED,并且能够在插入卡时接收IN管道上的状态更新。我不能做的是在控制管道上发送一个我认为应该是请求卡数据的报告请求。
我的问题是,如何设置此报告请求,以使HID读卡器向我发送卡数据(报告ID = 0x65,使用ID = 0x61C)?如果我的理解是正确的,这应该归结为对设置包中的标志的简单操作,但对于我来说,我不知道哪一个是正确的。
下面的代码用于设置在控制EP上发送的set_config事务,以操纵LED,这是众所周知的:
//Format the setup transaction
req.bmRequestType = USB_REQ_DIR_OUT | // 7 - Transfer is OUT
USB_REQ_TYPE_CLASS | // 5,6 - Transfer type is Class
USB_REQ_RECIP_INTERFACE; // 4 - recipient is the device
//Set the request type to USB_REQ_SET_CONFIGURATION
req.bRequest = USB_REQ_SET_CONFIGURATION;
//Set the descriptor type to string
req.wValue = (USB_DT_STRING << 8) | usb_dt; //wValue type. On Linux ==> 0x302 for init msg,
// 0x35f for led on control
req.wIndex = 0;
req.wLength = len; 该函数将传入的值0x302用于初始化消息,0x35f用于LED控制。然后,它启动一个传输,该传输将在索引0处移动包含所需命令的报告ID的缓冲区,然后移动一些数据(RGB值)。
最后,下面是我正在使用的设备的描述符:
设备描述符:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass %0
bDeviceSubClass %0
bDeviceProtocol %0
bMaxPacketSize0 64
idVendor 0x6352
idProduct 0x240a
bcdDevice 3.01
iManufacturer 1
iProduct 2
iSerial 3
bNumConfigurations 1
配置描述符:
bLength 9
bDescriptorType 2
wTotalLength 0x0022
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 3
bmAttributes 0x80
(总线供电)
MaxPower 500 MaxPower\
接口描述符:
bLength 9
bDescriptorType 4
bInterfaceNumber %0
bAlternateSetting %0
bNumEndpoints 1
bInterfaceClass 3人机接口设备
bInterfaceSubClass %0
bInterfaceProtocol %0
iInterface 4\
HID设备描述符:
bLength 9
bDescriptorType 33
bcdHID 1.11
不支持bCountryCode 0
bNumDescriptors 1
bDescriptorType 34报告
wDescriptorLength 730\
终结点描述符:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1输入
bmAttributes 3
传输型中断
同步类型无
使用类型数据
wMaxPacketSize 0x0040 1x 64字节
bInterval 46
任何指导或帮助都将非常感谢,
-Justin
发布于 2021-01-22 07:23:32
阿哈!我没有意识到16位wValue字段需要包含报告Id。解决方案有两个方面,首先将有效负载的第一个字节设置为应用程序级别上的报告ID。然后在问题中所示的低级请求描述符中设置wValue字段,如下所示:
req.wValue = (USB_DT_STRING << 8) | pkt;
https://stackoverflow.com/questions/65833788
复制相似问题