如何将消息从 USBSniffer 映射到 PyUSB



我正在尝试弄清楚如何为Microsoft LifeCam打开"TrueColor"。我有几个来自USBSniffer的大USB日志,以及当我单击Microsoft软件中的复选框时始终显示的一些序列。这是启用序列开头的请求,以及设备响应(顺便说一句,如果我误解了此数据,请纠正我):

[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:Python24Libsite-packagesusbcore.py", line 702, in ctrl_transfer
    self.__get_timeout(timeout)
  File "c:Python24Libsite-packagesusbbackendlibusb0.py", line 539, in ctrl_transfer
    timeout
  File "c:Python24Libsite-packagesusbbackendlibusb0.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])

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

从非常有用的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的类接口(参见"URB_FUNCTION_CLASS_INTERFACE"),因此RequestType特定于设备类(音频,物理...在本例中为视频)。GET_STATUS命令有效,因为它是标准类型。

所以一个更正确的命令是

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

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

编辑:为了完全真实,我需要根据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)

相关内容

  • 没有找到相关文章

最新更新