Post by Alan SternPost by Christopher MooreHello Everyone,
I'm using python's implementation of libusb (pyusb) to try to
communicate
with my phone device. I've finally understood the protocol and generally
get what the usb sniffer logs mean. Now it's finally time to start coding
this thing. Thank you all for your help so far on this mailing list to
get up to this point!
I've successfully been able to find the device, detach the hid driver from
it (which is what I'm after) , claim it's interface and reset it. I can
also successfully retrieve a report descriptor from it (HID device
report).
1) [ host -> device ] 04 c1 33 00 43 07 9a 4f 68
1a) 04 05 08 16 00 01 00 00 68
2) [ device -> host ] 03 83 34 00 43 00 00 00
3) [ host -> device ] 04 c1 33 00 43 07 9a 4f 68
3a) 04 05 08 16 00 00 00 00 68
4) [ device -> host ] 03 83 34 00 43 00 00 00
host -> device is the controlMsg sending a report to HID Report #4 in a 2
reqType = usb.TYPE_CLASS | usb.RECIP_INTERFACE | usb.ENDPOINT_OUT
reqBuffer = (0x04, 0xc1, 0x33, 0x00, 0x43, 0x07, 0x9a, 0x4f, 0x68)
handle.controlMsg(reqType, usb.REQ_SET_CONFIGURATION, reqBuffer, 00000304,
0x03)
I'm not familiar with the Python bindings. It would clarify the
code a little if you replaced REQ_SET_CONFIGURATION with something
closer to REQ_SET_REPORT, although the value (9) is the same for both.
The closest thing I was able to find in the python docs was
REQ_SET_CONFIGURATION
(http://wiki.erazor-zone.de/wiki:projects:python:pyusb:pydoc ... scroll
towards bottom)
Post by Alan SternPost by Christopher Mooreand then I do this same thing for line 1a) ... you can also see this in
the attached log.
Once I type this in the python terminal, I get returned: "9" in my python
prompt. In my logs, I recieve a setup packet: (21 09 04 03 03 00 09 00)
... is this correct?
It agrees with what you told Python to do. That doesn't mean it is
correct.
For instance, this says to send a Feature report with ID 4. Is that
what you want? Normally one would use an Output report, not a Feature
report; it depends on the device.
Is the interface number supposed to be 3? I rather doubt it, since the
log shows only one interface, number 0.
Report #4 is used to transport the host-to-device side of the CIT200's
control protocol. Report 4 is defined as Feature data, and thus it will
need to be sent by the host as a Feature-type Report.
The other report, Report #3 is an Input-Type Report (device -> host) ...
as seen in line #2
Also, just curious, how did you know this was a feature-type report? B/c
it had 0x03 in the returned setupPacket?
As for the interfaces:
Interface 1 - streaming ... Endpoint OUT (Speaker Out)
Interface 2 - streaming ... Endpoint In, iso transfer type (Mic In)
Interface 3 - HID Interface ... Endpoint IN, interrupt transfer type
The HID Interface on my device is interface #3 as shown in the output from
lsusb -vvv, and also in python doing the following:
# shows interface #3 is class 3 (HID)
for interface in config.interfaces:
print "Interface:",interface[0].interfaceNumber
for alt in interface:
print "Class:",alt.interfaceClass
Post by Alan SternPost by Christopher MooreAlso, what does "9" mean? 9 bytes successfully
sent?
"09" appears twice in the setup packet. The first appearance in
essentially REQ_SET_REPORT. The second appearance means that you are
going to send 9 bytes of report data. It doesn't mean that the bytes
were successfully sent.
Most likely the return value from that library call is the number of
bytes sent successfully.
Post by Christopher MooreNow, after, this according to the log, I should do a bulk/Interrupt read,
handle.interruptRead(usb.ENDPOINT_OUT,8) #doesn't work
It doesn't make much sense to read from an OUT endpoint.
Ok, I'll find out what the main endpoint is. That makes sense now.
Post by Alan SternPost by Christopher Moorehandle.interruptRead(endpoint.address,8) #also doesn't work
#usb.USBError: error submitting URB: No such file or directory
Is there something I'm missing?
Undoubtedly. I can't tell what it is, though, since you haven't
provided enough information.
Alan Stern
My code:
import usb
# linksys CIT200 Device Info
vendor_id = 5041
product_id = 29
buses = usb.busses()
for bus in buses :
for device in bus.devices :
if device.idVendor == vendor_id :
if device.idProduct == product_id :
# found the CIT200
linksys = device
# open device
handle = linksys.open()
# detach kernel drivers
handle.detachKernelDriver(3)
# setup interface and configs ... there are 4 interfaces for this device...
config = linksys.configurations[0]
interface = config.interfaces[3][0]
endpoint = interface.endpoints[0]
# set configuration and claim interface(s?)
#handle.setConfiguration(config)
"""
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
usb.USBError: could not set config 1: Device or resource busy
"""
handle.claimInterface(interface) # this actually assigns the interface
config I believe ...
handle.setAltInterface(interface)
# reset device
handle.reset()
# HID Report Descriptor
handle.getDescriptor(usb.DT_REPORT,0,0x9c,usb.ENDPOINT_OUT)
#(5, 11, 9, 1, 161, 1, 133, 1, 9, 6, 161, 2, 25, 176, 41, 187, 21, 0, 37,
12, 117, 4, 149, 1, 129, 0, 192, 9, 32, 21, 0, 37, 1, 117, 1, 149, 1, 129,
2, 9, 4, 161, 2, 5, 12, 9, 224, 21, 255, 37, 1, 117, 2, 149, 1, 129, 6, 9,
226, 21, 0, 37, 1, 117, 1, 149, 1, 129, 2, 192, 133, 2, 21, 0, 37, 1, 117,
1, 149, 1, 5, 11, 9, 32, 177, 2, 5, 11, 9, 24, 177, 2, 117, 6, 177, 7,5,
20, 9, 1, 38, 255, 0, 117, 8, 149, 1, 9, 44, 177, 2, 149, 15, 9, 44, 177,
2, 133, 3, 5, 20, 9, 1, 21, 0, 38, 255, 0, 117, 8, 149, 7, 9, 44, 129, 0,
133, 4, 5, 20, 9, 1, 21, 0, 38, 255, 0, 117, 8, 149, 8, 9, 44, 177, 0,
192)
"""
# shows interface #3 is class 3 (HID)
for interface in config.interfaces:
print "Interface:",interface[0].interfaceNumber
for alt in interface:
print "Class:",alt.interfaceClass
"""
reqType = usb.ENDPOINT_OUT | usb.TYPE_CLASS | usb.RECIP_INTERFACE
reqBuffer = (0x03 << 8) | 0x04 #(HID_REPORT_FEATURE << 8) + SEND_REPORT_ID
handle.controlMsg(reqType, usb.REQ_SET_CONFIGURATION, reqBuffer, 00000304,
0x03)
#(152, 243, 183, 0, 152, 243, 183, 0, 80, 41, 22, 8, 80, 41, 22, 8, 136,
45, 22, 8, 10, 0, 0, 0, 32, 228, 183, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 156, 42, 22, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 80, 160, 14, 8, 7, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 252, 41, 22, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
55, 147, 229, 164, 44, 224, 248, 183, 56, 223, 14, 8, 0, 0, 0, 0, 224,
217, 183, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 233, 249, 249,
172, 165, 248, 183, 44, 223, 14, 8, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 22,
169, 74, 181, 44, 162, 248, 183, 32, 223, 14, 8, 119, 168, 147, 27, 44,
163, 248, 183, 8, 223, 14, 8, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 62, 37, 3, 68, 223, 14, 8, 73, 2, 0, 0,
112, 241, 183, 0, 112, 241, 183, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 112, 241, 183, 0, 112, 241, 183, 0, 0, 0, 0, 0, 0, 0, 0, 0,
224, 123, 37, 3, 156, 0, 0, 0, 8, 223, 14, 8, 192, 222, 14, 8, 216, 222,
14, 8, 56, 223, 14, 8, 40, 231, 14, 8, 56, 223, 14, 8, 192, 224, 14, 8,
56, 223, 14, 8, 216, 222, 14, 8, 252, 222, 14, 8, 40, 231, 14, 8, 44,
223, 14, 8, 24, 222, 14, 8, 1, 0, 0, 0, 0, 0, 0, 0, 116, 66, 248, 183,
116, 66, 248, 183, 1, 0, 0, 0, 0, 0, 0, 0, 252, 107, 34, 3, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 240, 224, 14, 8, 68, 223, 14, 8,
180, 229, 14, 8,216, 222, 14, 8, 196, 221, 14, 8, 72, 222, 14, 8, 68,
223, 14, 8, 136, 221, 14, 8, 56, 223, 14, 8, 128, 225, 14, 8, 56, 223,
14, 8, 0, 224, 14, 8, 56, 223, 14, 8, 240, 224, 14, 8, 44, 223, 14, 8,
216, 222, 14, 8, 20, 223, 14, 8, 40, 231, 14, 8, 44, 223, 14,
8, 8, 223, 14, 8, 180, 222, 14, 8, 216, 222, 14, 8, 52, 228, 14, 8, 72,
222, 14, 8, 120, 234, 14, 8, 136, 221,14, 8, 56, 223, 14, 8, 128, 225,
14, 8, 44, 223, 14, 8, 0, 224, 14, 8, 56, 223, 14, 8, 240, 224, 14, 8,
252, 222, 14, 8, 216, 222, 14, 8, 28, 228, 14, 8, 72, 222, 14, 8, 68,
223, 14, 8, 136, 221, 14, 8, 56, 223, 14, 8, 128, 225, 14, 8, 56, 223,
14, 8, 0, 224, 14, 8, 56, 223, 14, 8, 240, 224, 14, 8, 44, 223, 14, 8,
180, 229, 14, 8, 192, 224, 14, 8, 44, 223, 14, 8, 72, 222, 14, 8, 68,
223, 14, 8, 136, 221, 14, 8, 56, 223, 14, 8, 128, 225, 14, 8, 56, 223,
14, 8, 0, 224, 14, 8, 56, 223, 14,8, 8, 223, 14, 8, 192, 222, 14, 8, 216,
222, 14, 8, 196, 221, 14, 8, 104, 230, 14, 8, 44, 223, 14, 8, 8, 223, 14,
8, 192, 222, 14, 8, 216, 222, 14, 8, 36, 222, 14, 8, 104, 230, 14, 8, 44,
223, 14, 8, 128, 225, 14, 8, 252, 222, 14, 8, 104, 230, 14, 8, 240, 222,
14, 8, 8, 223, 14, 8)
#reqBuffer = [0] * 8
reqType = usb.TYPE_CLASS | usb.RECIP_INTERFACE | usb.ENDPOINT_OUT
#handle.controlMsg(reqType, usb.REQ_SET_CONFIGURATION, reqBuffer,
00000304, 0x03)
# returns 8
""" Look Here (Begin) """
reqBuffer = (0x04, 0xc1, 0x33, 0x00, 0x43, 0x07, 0x9a, 0x4f, 0x68)
handle.controlMsg(reqType, usb.REQ_SET_CONFIGURATION, reqBuffer, 00000304,
0x03)
#returns 9
reqBuffer = (0x04, 0x05, 0x08, 0x16, 0x00, 0x01, 0x00, 0x00, 0x68)
handle.controlMsg(reqType, usb.REQ_SET_CONFIGURATION, reqBuffer, 00000304,
0x03)
#returns 9
handle.interruptRead(usb.ENDPOINT_OUT,8) #doesn't work
handle.interruptRead(endpoint.address,8) #doesn't work
#usb.USBError: error submitting URB: No such file or directory
""" Look here (END) """
# release device
handle.releaseInterface()
--------------------------------
Do you need any more information?
Thanks
Christopher