我的问题与此处提出的问题非常相似:libusb interrupt transfer
我正在逆向工程驱动程序Linux-G13_1.0-r44.zip
在此处找到:http://code.google.com/p/linux-g13-driver/downloads/list
让它在RHEL5下工作。
似乎一切正常,但是我从libusb_interrupt_transfer获得的唯一响应是超时错误“-7”
输出:“lsusb -v -d 046d:c21c”
Bus 006 Device 010: ID 046d:c21c Logitech, Inc.
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x046d Logitech, Inc.
idProduct 0xc21c
bcdDevice 2.03
iManufacturer 0
iProduct 1 G13
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 41
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
MaxPower 500mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0 No Subclass
bInterfaceProtocol 0 None
iInterface 0
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.11
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 61
Report Descriptor: (length is 61)
Item(Global): Usage Page, data= [ 0x00 0xff ] 65280
(null)
Item(Local ): Usage, data= [ 0x00 ] 0
(null)
Item(Main ): Collection, data= [ 0x01 ] 1
Application
Item(Global): Logical Minimum, data= [ 0x00 ] 0
Item(Global): Logical Maximum, data= [ 0xff 0x00 ] 255
Item(Local ): Usage, data= [ 0x01 ] 1
(null)
Item(Global): Report ID, data= [ 0x01 ] 1
Item(Global): Report Count, data= [ 0x07 ] 7
Item(Global): Report Size, data= [ 0x08 ] 8
Item(Main ): Input, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Global): Report ID, data= [ 0x03 ] 3
Item(Local ): Usage, data= [ 0x02 ] 2
(null)
Item(Global): Report Count, data= [ 0xdf 0x03 ] 991
Item(Main ): Output, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Global): Report ID, data= [ 0x07 ] 7
Item(Local ): Usage, data= [ 0x03 ] 3
(null)
Item(Global): Report Count, data= [ 0x04 ] 4
Item(Main ): Feature, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Global): Report ID, data= [ 0x04 ] 4
Item(Local ): Usage, data= [ 0x04 ] 4
(null)
Item(Main ): Feature, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Global): Report ID, data= [ 0x05 ] 5
Item(Local ): Usage, data= [ 0x05 ] 5
(null)
Item(Main ): Feature, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Global): Report ID, data= [ 0x06 ] 6
Item(Local ): Usage, data= [ 0x06 ] 6
(null)
Item(Global): Report Count, data= [ 0x01 0x01 ] 257
Item(Main ): Feature, data= [ 0x02 ] 2
Data Variable Absolute No_Wrap Linear
Preferred_State No_Null_Position Non_Volatile Bitfield
Item(Main ): End Collection, data=none
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0008 1x 8 bytes
bInterval 2
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 1
在Constants.h中定义:
#define G13_INTERFACE 0
#define G13_KEY_ENDPOINT 1
#define G13_LCD_ENDPOINT 2
#define G13_KEY_READ_TIMEOUT 0
#define G13_VENDOR_ID 0x046d
#define G13_PRODUCT_ID 0xc21c
#define G13_REPORT_SIZE 8
#define G13_LCD_BUFFER_SIZE 0x3c0
#define G13_NUM_KEYS 40
G13.cpp:
#include "Constants.h"
...
int G13::read() {
unsigned char buffer[G13_REPORT_SIZE];
int size;
cout << "prebuffer: " << buffer << "\n";
cout << "presize: " << size << "\n";
int error = libusb_interrupt_transfer(handle, LIBUSB_ENDPOINT_IN | G13_KEY_ENDPOINT, buffer, G13_REPORT_SIZE, &size, 1000);
cout << "buffer: " << buffer << "\n";
cout << "size: " << size << "\n";
if (error && error != LIBUSB_ERROR_TIMEOUT) {
std::map<int, std::string> errors;
errors[LIBUSB_SUCCESS] = "LIBUSB_SUCCESS";
errors[LIBUSB_ERROR_IO] = "LIBUSB_ERROR_IO";
errors[LIBUSB_ERROR_INVALID_PARAM] = "LIBUSB_ERROR_INVALID_PARAM";
errors[LIBUSB_ERROR_ACCESS] = "LIBUSB_ERROR_ACCESS";
errors[LIBUSB_ERROR_NO_DEVICE] = "LIBUSB_ERROR_NO_DEVICE";
errors[LIBUSB_ERROR_NOT_FOUND] = "LIBUSB_ERROR_NOT_FOUND";
errors[LIBUSB_ERROR_BUSY] = "LIBUSB_ERROR_BUSY";
errors[LIBUSB_ERROR_TIMEOUT] = "LIBUSB_ERROR_TIMEOUT";
errors[LIBUSB_ERROR_OVERFLOW] = "LIBUSB_ERROR_OVERFLOW";
errors[LIBUSB_ERROR_PIPE] = "LIBUSB_ERROR_PIPE";
errors[LIBUSB_ERROR_INTERRUPTED] = "LIBUSB_ERROR_INTERRUPTED";
errors[LIBUSB_ERROR_NO_MEM] = "LIBUSB_ERROR_NO_MEM";
errors[LIBUSB_ERROR_NOT_SUPPORTED] = "LIBUSB_ERROR_NOT_SUPPORTED";
errors[LIBUSB_ERROR_OTHER] = "LIBUSB_ERROR_OTHER ";
cerr << "Error while reading keys: " << error << " (" << errors[error]
<< ")" << endl;
cerr << "Stopping daemon" << endl;
return -1;
}
if (size == G13_REPORT_SIZE) {
parse_joystick(buffer);
parse_keys(buffer);
send_event(EV_SYN, SYN_REPORT, 0);
}
return 0;
}
“sudo ./Linux-G13-Driver”,同时在设备上粘贴键,返回:
Found Device: 0x1abebd20
Kernel driver detached
Device Loaded: 0x1abebd20
loading /root/.g13/bindings-0.properties
prebuffer: �
presize: 255
buffer: #
size: 0
prebuffer: #
presize: 0
buffer: #
size: 0
prebuffer: #
presize: 0
buffer: #
size: 0
prebuffer: #
presize: 0
^C
Segmentation fault
我包含了prebuffer和preize行只是为了证明它实际上正在初始化缓冲区。同样正如我在顶部引用的帖子中提到的Arne,设备似乎正常打开,并且两个接口都被正确声明。他提到的唯一让我感到困惑的是“SET_INTERFACE”和“SET_CONFIGURATION”,但也许这只是一个Windows的东西?
我应该注意,我必须做两件事才能在rhel5上正确构建:
必须在一堆头文件中添加“include Linux / interface.h”行
必须构建libusb-1.0,因为它没有包含在我特定的rhel5版本中
我对linux有点新意,所以我尝试了libusb-1.0.8和libusb-1.0.9都无济于事。我的Windows直觉告诉我libusb构建是我的问题,并且库实际上并没有因为某些原因从usb设备接收中断。
我提前为任何重大的noob错误道歉。有没有人有任何想法?