如何将消息从USBSniffer映射到PyUSB?

时间:2012-11-13 23:07:36

标签: usb pyusb

我正在试图找出如何为Microsoft LifeCam启用“TrueColor”。我有一些来自USBSniffer的大型USB日志,以及当我点击微软软件中的复选框时一直显示的一些序列。这是从启用序列开始的请求,以及设备响应(如果我误解了这些数据,请纠正我):

[156918643 ms] UsbSnoop - FilterDispatchAny(ac56afd2) : IRP_MJ_INTERNAL_DEVICE_CONTROL
[156918643 ms] UsbSnoop - FdoHookDispatchInternalIoctl(ac56b1ea) : fdo=88b25448, Irp=889911d8, IRQL=0
[156918643 ms]  >>>  URB 1482 going down  >>> 
-- URB_FUNCTION_CLASS_INTERFACE:
  TransferFlags          = 00000001 (USBD_TRANSFER_DIRECTION_IN, ~USBD_SHORT_TRANSFER_OK)
  TransferBufferLength = 00000002
  TransferBuffer       = abb04b86
  TransferBufferMDL    = 00000000
  UrbLink                 = 00000000
  RequestTypeReservedBits = 00000000
  Request                 = 00000085
  Value                   = 00001600
  Index                   = 00000500
[156918644 ms] UsbSnoop - MyInternalIOCTLCompletion(ac56b126) : fido=00000000, Irp=889911d8, Context=894d6c98, IRQL=2
[156918644 ms]  <<<  URB 1482 coming back  <<< 
-- URB_FUNCTION_CONTROL_TRANSFER:
  PipeHandle           = 885639a0
  TransferFlags        = 0000000b (USBD_TRANSFER_DIRECTION_IN, USBD_SHORT_TRANSFER_OK)
  TransferBufferLength = 00000002
  TransferBuffer       = abb04b86
  TransferBufferMDL    = 8837fee0
    00000000: 40 00
  UrbLink              = 00000000
  SetupPacket          =
    00000000: a1 85 00 16 00 05 02 00

现在,我想通过PyUSB发送我见过的请求序列,但是当我发送第一个请求时,我得到:

>>> ret = dev.ctrl_transfer(0x80, 0x85, 0x1600, 0x0500, 8)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "c:\Python24\Lib\site-packages\usb\core.py", line 702, in ctrl_transfer
    self.__get_timeout(timeout)
  File "c:\Python24\Lib\site-packages\usb\backend\libusb0.py", line 539, in ctrl_transfer
    timeout
  File "c:\Python24\Lib\site-packages\usb\backend\libusb0.py", line 387, in _check
    raise USBError(errmsg, ret)
usb.core.USBError: (None, 'usb_control_msg: invalid request 0x85')

对于它的价值,一个简单的GET_STATUS似乎有效:

>>> ret = dev.ctrl_transfer(0x80, 0, 0, 0, 8)
>>> print ret
array('B', [0, 0])

为什么在一种情况下得到回答的请求在另一种情况下无效?句法?设备状态?

1 个答案:

答案 0 :(得分:2)

从非常有帮助的USB Made Simple,请求类型的最高3位格式如下:

D7 Data direction
0 - Host-to-device
1 - Device-to-host
D6:5 Type
0 = Standard
1 = Class
2 = Vendor
3 = Reserved

日志说我使用USB的Class接口(参见&#34; URB_FUNCTION_CLASS_INTERFACE&#34;),因此RequestType特定于设备类(音频,物理...在此案例视频)。 GET_STATUS命令有效,因为它是标准类型。

所以更正确的命令是

ret = dev.ctrl_transfer(0xa0, 0x85, 0x1600, 0x0500, 8)

我说 more 是正确的,因为该命令会返回数据,但它仍然不是我期望的数据!

编辑:为了完整的真实性,我需要根据USB Made Simple的其余请求类型表指定收件人作为接口:

D4:0 Recipient
0 = Device
1 = Interface
2 = Endpoint
3 = Other
4-31 = Reserved

...并且还将长度设置为与嗅探请求相同,因此该命令的真实版本为:

ret = dev.ctrl_transfer(0xa1, 0x85, 0x1600, 0x0500, 2)