libusb中断传输 [英] libusb interrupt transfer

查看:887
本文介绍了libusb中断传输的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为定制的HID USB设备(控制面板上的一些按钮和LED)逆向工程。驱动程序只在Windows上可用,我们需要一个* nix实现。

I need to reverse engineer a driver for custom made HID USB device (some buttons and leds on an control panel). The driver is only available on Windows and we need a *nix implementation.

设备显然是一个HID设备,虽然不是一个特定的类。它提供了两个接口,每个接口都有一个中断端点。

The device apparently is a HID device although not of a particular class. It provides two interfaces each with a single interrupt endpoint.

我的设置目前涉及一个在Ubuntu主机上运行Windows的VirtualBox,通过Wireshark捕获USB流量。协议是相当简单,我已经获得了一个很好的理解。

My setup currently involves a VirtualBox running Windows on a Ubuntu host to capture the USB traffic via Wireshark. The protocol is rather simple and I already gained a rather good understanding.

我在一个简单的C ++控制台程序中使用libusb-1.0进行原型开发。我已经设法通过发出SET_REPORT控制传输来切换LED,但是在通过传输中断接收按钮按下时遇到困难。

I am using libusb-1.0 in a simple C++ console program for prototyping. I already managed to toggle LEDs by issuing a SET_REPORT control transfer but struggle in receiving button presses via interrupt in transfers.

实际上,以下调用块永远:

In fact the following call blocks forever:

unsigned char bytes[8] = { 0 };
int len = 0;
int ret = libusb_interrupt_transfer(handle, 0x81, bytes, 8, &len, 0); 

当在Wireshark检查生成的URB时,它看起来就像在Windows会话捕获的等效。仍然我从未收到设备的回复。

When inspecting the resulting URB in Wireshark it looks exactly like the equivalent captured at the Windows session. Still I never get a reply from the device.

我失去了一些设置。请注意,设备已正确打开,且设备提供的两个接口均已成功提出索赔。即使在我的linux应用程序中,通过控制传输的输入报告也会消失。

I fell I am missing some setting. Note that the device is properly opened and both interfaces provided by the device have been sucessfully claimed. Input reports by means of control transfers are coming trough, even in my linux application.

感谢任何指针!
Arne

Thanks for any pointer! Arne

附录I:
我想知道我应该如何指定使用 libusb_interrupt_transfer()?

附录II:
当将Windows驱动程序的请求与上面生成的请求代码在Wireshark我没有看到任何差异(URB中的相同值)。但是,只有当由Windows驱动程序发出的中断传输返回时。

Addendum II: When comparing the requests made by the windows driver to the one generated by the above code in Wireshark I don't see any difference (same values in URB). But still, only when issued by the Windows driver the interrupt transfer returns.

在Wireshark中检查Windows驱动程序通信时,除了各种 GET_DESCRIPTOR(...)。最重要的是: SET_INTERFACE SET_CONFIGURATION 因此,我怀疑问题与库相关或如何使用,

When inspecting the Windows driver communication in Wireshark I dont see any control transfers other than various GET_DESCRIPTOR(...). Most important: no SET_INTERFACE or SET_CONFIGURATION Thus I suspect the problem is related to the library or how I use it and is not related to the device.

推荐答案

您发布的代码有问题。你为定义 bytes 而编写的语法不会产生一个8字节数组,但是你要求libusb将8个字节写入该地址,这样你可能会得到一个错误,内存损坏。尝试这样:

There is a problem with the code you posted. The syntax you wrote for defining bytes will not result in an 8-byte array, but you are requesting that libusb write 8 bytes in to that address so you might get an error or memory corruption. Try this instead:

unsigned char buffer[8];
int len = 0;
int ret = libusb_interrupt_transfer(handle, 0x81, buffer, sizeof(buffer), &len, 0);

每个HID报表都有自己的端点,因此您可以通过指定正确的端点。您指定了Endpoint 1 IN(0x81)。您确定端点是在设备的描述符中定义的吗?也许你应该得到描述符(在Ubuntu中的 lsusb -v ),并在这里发布,以便我们可以检查它们。

Each HID report has its own endpoint, so you specify which report you want to receive by specifying the correct endpoint. You specified Endpoint 1 IN (0x81). Are you sure that endpoint is defined in the device's descriptors? Maybe you should get the descriptors (with lsusb -v in Ubuntu) and post them here so we can check them.

这篇关于libusb中断传输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆