|
From: Chris E <sp...@gm...> - 2018-07-27 17:31:52
|
Awesome. :)
If you were using usbpcap, for what it's worth, you can set up filters to
only look at single USB ports/hubs/hosts.
I go over it a little bit in some of the documentation I wrote. Google
"EspoTek Biryani7". There's a little bit of USB hacking stuff there. :)
Cheers,
~Chris
On Fri, 27 Jul 2018 at 08:05, Bruce Gamblin <br...@ze...> wrote:
> Hey Chris,
>
>
>
> Thanks for the help! I finally figured it out.
>
> The Wireshark ability to sniff USB packets was the tip I needed. I had no
> idea it could do that.
>
>
>
> I used Wireshark on Windows to sniff the packets on my USB to serial cable
> and then used Tera Term to setup the line characteristics I wanted and also
> used their binary file data transfer feature to send the actual data across
> the wire I wanted to send.
>
>
>
> Then I had to isolate my device from the rater ridiculous amount of
> traffic in the trace. Then cut out the repeating config commands that
> Windows seems to think it needs to send over and over ad nauseum.
>
>
>
> Then, I finally had the info I needed to realize I was both missing
> commands and I had also made a bad assumption in my usage of the libusb API
> when sending 0xc0 and 0x40 command types.
>
>
>
> So, now I have a ‘C’ program that can send the data I want using the USB
> to serial PL2303 chip based cable.
>
>
>
> Thanks again,
>
>
>
> Bruce.
>
>
>
> *From:* Chris E <sp...@gm...>
> *Sent:* Wednesday, July 25, 2018 10:55 PM
> *To:* Bruce Gamblin <br...@ze...>
> *Cc:* Libusb mailing list <lib...@li...>
> *Subject:* Re: [libusb] Problem using Prolific USB-Serial Controller on
> Android 6
>
>
>
> Haha, I don't think it's that much of a mystery. The packets could be
> being sent correctly, but you've just missed one or two steps of the
> configuration and so the device's output is not enabled. An ACK from a USB
> device doesn't mean anything except that the device saw the packet. :)
>
>
>
> Let us know how you go.
>
>
>
> ~Chris
>
>
>
> On Thu, 26 Jul 2018 at 12:45, Bruce Gamblin <br...@ze...> wrote:
>
> Hey Chris,
>
>
>
> Thanks for the suggestions. I don’t actually have a Windows compiler (and
> sadly Android doesn’t ship with either tcpdump or the usbmon kernel
> module). Tomorrow I’ll start looking into compiling it all on a non-Android
> Linux system where I have tcpdump and usbmon available and see what I get.
> I’ll post any results back here once I’m done with that although that may
> take a little while.
>
>
>
> The xusb program is already calling the
> libusb_set_auto_detach_kernel_driver() API. It’s return code indicates
> success so I’m not sure where to take things there….
>
>
>
> The mystery for me here is that libusb clearly thinks it worked but
> neither my oscilloscope nor programs like Tera Term see any characters
> coming out.
>
>
>
> Thanks, I appreciate the help.
>
>
>
> Bruce.
>
>
>
> *From:* Chris E <sp...@gm...>
> *Sent:* Wednesday, July 25, 2018 6:03 PM
> *To:* Bruce Gamblin <br...@ze...>
> *Cc:* lib...@li...
> *Subject:* Re: [libusb] Problem using Prolific USB-Serial Controller on
> Android 6
>
>
>
> G'day Bruce. Dumb question: have you tried running your code on Desktop,
> with the kernel driver disabled?
>
>
>
> That would rule out any Android specific issues. Also, are you sure
> you're sending the right packets? Wireshark can sniff USB stuff. Try to
> copy the exact sequence that the kernel driver sends and see if that works.
>
>
>
> If libusb said it worked, then it probably worked. I've used it on
> Android in the past and it was very willing to display errors when your
> permissions etc. were wrong.
>
>
>
> Happy hacking.
>
> - Chris
>
>
>
>
>
> On Thu., 26 Jul. 2018, 6:52 am Bruce Gamblin, <br...@ze...> wrote:
>
> Hi,
>
>
>
> I'm trying to get a USB to serial cable working (i.e. serial 9 pin RS232)
> using libusb on Android 6.
>
> I have root access on the Android box and 'su' is
> available.
>
> SeLinux is set to Permissive
>
>
>
> I'm using a Prolific USB-Serial Controller with a PL2303 chip under the
> hood (I think). This is an off the shelf cable, not some custom thing. I've
> tried this with 2 different cables and had the same result.
>
>
>
> I have the TX pin on the 9 pin RS232 end of the cable connected to a
> scope. If I connect the USB end to my laptop a COM port is created and I
> can use Tera Term to send characters. The scope shows the activity on the
> TX line. So, I know the cable works.
>
>
>
> If I then move the USB end to my android box no entry shows up as
> /dev/ttyUSBx (in fact nothing directly under /dev changes) BUT there are
> new entries under /dev/bus/usb ... in fact mine is /dev/bus/usb/007 right
> now:
>
> cat /dev/bus/usb/001/007 | hexdump
>
> 0000000 0112 0110 0000 4000 067b 2303 0400 0201
>
> 0000010 0100 0209 0027 0101 8000 0932 0004 0300
>
> 0000020 00ff 0000 0507 0381 000a 0701 0205 4002
>
> 0000030 0000 0507 0283 0040 0000
>
>
>
> dmesg shows a device was connected but no serial kernel driver is tied to
> it that I can see:
>
> [14971.774062@1] usb 1-2: new full-speed USB device number 7 using
> xhci-hcd
>
>
>
> I'm under the impression that libusb is perfectly happy and capable of
> using the device via the /dev/bus/usb/001 entry.
>
> I modified the sample xusb program to try to make it perform a bulk write
> on the endpoint at address 0x02.
>
> I set debug to max
>
>
>
> The API says it did it with no errors but nothing shows up on the scope.
>
>
>
> I've tried numerous additional setup steps using control transfers before
> doing the bulk transfer based on info that I found online regarding the
> PL2303 chip (which I believe is what is being used). Nothing has worked.
> The current version is doing the following after grabbing the interface:
>
> Init - based on what I found online....The presence of
> this seems to have changed nothing
>
> libusb_control_transfer(handle, 0xc0, 0x01, 0x8484, 0,
> buff, 1, 1000);
>
> buff[0] = 0x00;
>
> libusb_control_transfer(handle, 0x40, 0x01, 0x0404, 0,
> buff, 1, 1000);
>
> libusb_control_transfer(handle, 0xc0, 0x01, 0x8484, 0,
> buff, 1, 1000);
>
> libusb_control_transfer(handle, 0xc0, 0x01, 0x8383, 0,
> buff, 1, 1000);
>
> libusb_control_transfer(handle, 0xc0, 0x01, 0x8484, 0,
> buff, 1, 1000);
>
> buff[0] = 0x01;
>
> libusb_control_transfer(handle, 0x40, 0x01, 0x0404, 0,
> buff, 1, 1000);
>
> libusb_control_transfer(handle, 0xc0, 0x01, 0x8484, 0,
> buff, 1, 1000);
>
> libusb_control_transfer(handle, 0xc0, 0x01, 0x8383, 0,
> buff, 1, 1000);
>
> buff[0] = 0x01;
>
> libusb_control_transfer(handle, 0x40, 0x01, 0x0, 0, buff,
> 1, 1000);
>
> buff[0] = 0x00;
>
> libusb_control_transfer(handle, 0x40, 0x01, 0x1, 0, buff,
> 1, 1000);
>
> buff[0] = 0x24;
>
> libusb_control_transfer(handle, 0x40, 0x01, 0x2, 0, buff,
> 1, 1000);
>
>
>
> Setup DTR/RTS
>
> libusb_control_transfer(handle, 0x21, 0x22, (0x1 | 0x2),
> 0, NULL, 0, 0);
>
>
>
> Setup Line Encoding
>
> unsigned char encoding[] = { 0x80, 0x25, 0x00, 0x00, 0x00,
> 0x00, 0x08 };
>
> libusb_control_transfer(handle, 0x21, 0x20, 0, 0,
> encoding, sizeof(encoding), 0);
>
>
>
> Read Line Encoding Back to prove it worked:
>
> buff[0] = 0xab;
>
> buff[1] = 0xab;
>
> buff[2] = 0xab;
>
> buff[3] = 0xab;
>
> buff[4] = 0xab;
>
> buff[5] = 0xab;
>
> buff[6] = 0xab;
>
> libusb_control_transfer(handle, 0xa1, 0x21, 0x0, 0, buff,
> 7, 1000);
>
> printf("Received: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
> buff[0], buff[1], buff[2], buff[3], buff[4], buff[5], buff[6]);
>
>
>
> int actual_length=0;
>
> char hello[16];
>
> hello[0] = 0xAA;
>
> hello[1] = 0x11;
>
> hello[2] = 0xFE;
>
> hello[3] = 0x01;
>
> hello[4] = 0x00;
>
> hello[5] = 0x10;
>
> int rc = libusb_bulk_transfer(handle,
> xmitEndpoint->bEndpointAddress, (unsigned char *)hello, 6, &actual_length,
> 2000);
>
> printf("Xfter rc = %d, xfered size = %d\n\n", rc,
> actual_length);
>
>
>
> And after all that, it says it did it fine but nothing shows up on the
> scope. If I leave out all the init and setup stuff it still does the same
> thing – says everything is OK but nothing on the TX pins. I also tried
> connecting cables together so anything sent would show up on my laptop (and
> also, the laptop could send characters back). When I tried to do a receive
> with a 10 second TMO it just timed out and I received nothing on the
> Android box.
>
>
>
> It's almost like the control interface is working and I can talk to and
> configure the PL2303 but when I try to perform a transfer nothing works but
> the API indicates that everything worked fine.
>
>
>
>
>
>
>
> Here's the output of xusb (vendor 67b, product 2303) ... there's some
> extra verbiage from my printf's:
>
> root@p230:/data/local/tmp # xusb -i 67b:2303
>
> Using libusb v1.0.22.11314
>
>
>
> Opening device 067B:2303...
>
>
>
> Device properties:
>
> bus number: 1
>
> port path: 2 (from root hub)
>
> speed: 12 Mbit/s (USB FullSpeed)
>
>
>
> Reading device descriptor:
>
> length: 18
>
> device class: 0
>
> S/N: 0
>
> VID:PID: 067B:2303
>
> bcdDevice: 0400
>
> iMan:iProd:iSer: 1:2:0
>
> nb confs: 1
>
>
>
> Reading BOS descriptor: no descriptor
>
>
>
> Reading first configuration descriptor:
>
> nb interfaces: 1
>
> interface[0]: id = 0
>
> interface[0].altsetting[0]: num endpoints = 3
>
> Class.SubClass.Protocol: FF.00.00
>
> endpoint[0].address: 81
>
> endpoint[0].attributes: 0x3
>
> max packet size: 000A
>
> polling interval: 01
>
> endpoint[1].address: 02
>
> endpoint[1].attributes: 0x2
>
> max packet size: 0040
>
> polling interval: 00
>
> endpoint[2].address: 83
>
> endpoint[2].attributes: 0x2
>
> max packet size: 0040
>
> polling interval: 00
>
> Set Config 1
>
>
>
> Claiming interface 0...
>
> Claimed Interface
>
> Test Read of 0x8484
>
> Received: 0x2
>
> Received: 0x2
>
> Received: 0xff
>
> Received: 0x2
>
> Received: 0x2
>
> Received: 0xff
>
> Send Control commands
>
> Set Line State DTR/RTS
>
> Set line encoding 9600 8N1
>
> Get Line Status
>
> Received: 0x80 0x25 0x0 0x0 0x0 0x0 0x8
>
> Try bulk Xfer to 2....
>
> Xfter rc = 0, xfered size = 6
>
>
>
>
>
> Reading string descriptors:
>
> String (0x01): "Prolific Technology Inc. "
>
> String (0x02): "USB-Serial Controller D"
>
>
>
> Releasing interface 0...
>
> Closing device...
>
>
>
>
>
> Thanks, any help or insight is appreciated.
>
>
>
> Bruce.
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> libusb-devel mailing list
> lib...@li...
> https://lists.sourceforge.net/lists/listinfo/libusb-devel
>
>
|