nesto-software / USBProxy

A USB proxy for rpi 4b, based on libUSB & gadgetFS - maintained by Nesto
GNU General Public License v2.0
43 stars 12 forks source link

Printer not detected on Windows #24

Open Leon90PL opened 3 years ago

Leon90PL commented 3 years ago

Hi, I'm using USBProxy with NanoPi Neo and Epic430 printer, it's working as expected with Linux and some Windows hosts but not working with specific Windows host.

Running under kernel 5.3.0-rc7
CP: String DeviceProxy = DeviceProxy_LibUSB
CP: String HostProxy = HostProxy_GadgetFS
Loading plugins from /usr/local/lib/USBProxy/
vendorId=ffffffff
productId=ffffffff
cleaning up /tmp
removing 1
Made directory /tmp/gadget-bLJDJP for gadget
Printing Config data
    Strings: 2
        DeviceProxy: DeviceProxy_LibUSB
        HostProxy: HostProxy_GadgetFS
    Vectors: 1
        Plugins:
            PacketFilter_StreamLog
Pointer: 1
        PacketFilter_StreamLog::file: 0xb6d2ad10
Connected to device: 0613:2043@02 TransAct - Ithaca USB Printer

Error sending setup packet: Pipe error
Device: 12 01 00 02 00 00 00 40 13 06 43 20 01 01 01 02 03 01
  Manufacturer: TransAct
  Product:      Ithaca USB Printer
  Serial:       EPIC 430
    *Config(1): 09 02 37 00 02 01 00 c0 00
        Interface(0):
            *Alt(0): 09 04 00 00 02 ff 00 00 05
               Name: USB COM
                EP(84): 07 05 84 02 40 00 00
                EP(02): 07 05 02 02 40 00 00
        Interface(1):
            *Alt(0): 09 04 01 00 02 07 01 02 04
               Name: USB Prn
                EP(84): 07 05 84 02 40 00 00
                EP(02): 07 05 02 02 40 00 00
old bInterval: 00
calculated new bInterval: 80000000
old bInterval: 00
calculated new bInterval: 80000000
old bInterval: 00
calculated new bInterval: 80000000
old bInterval: 00
calculated new bInterval: 80000000

    00 00 00 00 09 02 37 00 02 01 00 c0 00 09 04 00 00 02 ff 00 00 05 07 05 84 02 40 00 00 07 05 02
    02 40 00 00 09 04 01 00 02 07 01 02 04 07 05 84 02 40 00 00 07 05 02 02 40 00 00 09 02 37 00 02
    01 00 c0 00 09 04 00 00 02 ff 00 00 05 07 05 84 02 40 00 00 07 05 02 02 40 00 00 09 04 01 00 02
    07 01 02 04 07 05 84 02 40 00 00 07 05 02 02 40 00 00 12 01 00 02 00 00 00 40 13 06 43 20 01 01
    01 02 03 01
searching in [/tmp/gadget-bLJDJP]
Starting setup writer thread (22902) for EP00.
Starting setup reader thread (22901) for EP00.
gadgetfs: event 1
gadgetfs: event 4
gadgetfs: event 2
gadgetfs: event 4
gadgetfs: event 1
gadgetfs: event 2
gadgetfs: event 1
[80 06 00 03 00 00 ff 00]
[80 06 00 03 00 00 04 00]: 04 03 09 04
[80 06 03 03 09 04 ff 00]
[80 06 03 03 09 04 2c 00]: 
    2c 03 45 00 50 00 49 00 43 00 20 00 34 00 33 00 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00
[80 06 00 03 00 00 ff 00]
[80 06 00 03 00 00 04 00]: 04 03 09 04
[80 06 02 03 09 04 ff 00]
[80 06 02 03 09 04 26 00]: 
    26 03 49 00 74 00 68 00 61 00 63 00 61 00 20 00 55 00 53 00 42 00 20 00 50 00 72 00 69 00 6e 00
    74 00 65 00 72 00
[80 06 00 03 00 00 ff 00]
[80 06 00 03 00 00 04 00]: 04 03 09 04
[80 06 02 03 09 04 ff 00]
[80 06 02 03 09 04 26 00]: 
    26 03 49 00 74 00 68 00 61 00 63 00 61 00 20 00 55 00 53 00 42 00 20 00 50 00 72 00 69 00 6e 00
    74 00 65 00 72 00
Sending ACK
[00 09 01 00 00 00 00 00]
Opened EP84
Opened EP02
Fail on open EP84 16 Device or resource busy
Starting writer thread (22906) for EP02.
Starting reader thread (22907) for EP84.
Starting reader thread (22905) for EP02.
Starting writer thread (22908) for EP84.
Sending ACK
[80 06 05 03 09 04 ff 00]
[80 06 05 03 09 04 10 00]: 10 03 55 00 53 00 42 00 20 00 43 00 4f 00 4d 00
[80 06 04 03 09 04 ff 00]
[80 06 04 03 09 04 10 00]: 10 03 55 00 53 00 42 00 20 00 50 00 72 00 6e 00
[a1 00 00 00 00 01 f1 03]
[a1 00 00 00 00 01 2e 00]: 
    00 2e 4d 46 47 3a 41 34 32 30 38 43 30 31 30 32 39 35 2d 3b 4d 44 4c 3a 45 34 33 30 20 50 63 4f
    53 3b 43 4c 53 3a 50 52 49 4e 54 45 52 3b

gadgetfs: event 2
gadgetfs: event 1
gadgetfs: event 2
gadgetfs: event 1
Sending ACK
[00 09 01 00 00 00 00 00]
Fail on open EP84 16 Device or resource busy
Sending ACK
gadgetfs: event 2
gadgetfs: event 1
gadgetfs: event 2
gadgetfs: event 1
Sending ACK
[00 09 01 00 00 00 00 00]
Fail on open EP84 16 Device or resource busy
Sending ACK
02[3]: 01 5a 0d
02[3]: 01 5a 0d
gadgetfs: event 2
gadgetfs: event 1
gadgetfs: event 2
gadgetfs: event 1
Sending ACK
[00 09 01 00 00 00 00 00]
Fail on open EP84 16 Device or resource busy
Sending ACK
gadgetfs: event 2
gadgetfs: event 1
gadgetfs: event 2
gadgetfs: event 1
Sending ACK
[00 09 01 00 00 00 00 00]
Fail on open EP84 16 Device or resource busy
Sending ACK
gadgetfs: event 2
gadgetfs: event 1
gadgetfs: event 2
gadgetfs: event 1
Sending ACK
[00 09 01 00 00 00 00 00]
Fail on open EP84 16 Device or resource busy
Sending ACK
gadgetfs: event 4
gadgetfs: event 2
gadgetfs: event 1
gadgetfs: event 2
gadgetfs: event 1
[80 06 00 03 00 00 ff 00]
[80 06 00 03 00 00 04 00]: 04 03 09 04
[80 06 03 03 09 04 ff 00]
[80 06 03 03 09 04 2c 00]: 
    2c 03 45 00 50 00 49 00 43 00 20 00 34 00 33 00 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00

Then host reports error. I also grabbed tcpdump from NanoPi https://imgur.com/a/ARsMJGZ Can anyone explain why host could reject device?

MartinLoeper commented 3 years ago

Hi @Leon90PL, did you try out the changes in the mweal-ed fork? We merged them in dev today and it fixed many issues (e.g. graceful exit, hotplugging, memory leaks). Could you please confirm your issue persists with the dev version? Which OS are you running on your NanoPi?

Leon90PL commented 3 years ago

Hi I tried with dev branch but I guess there is a problem with disconnection. Im using Armbian

Version 0.2
Running under kernel 5.3.0-rc7
CP: String DeviceProxy = DeviceProxy_LibUSB
CP: String HostProxy = HostProxy_GadgetFS
Loading plugins from /usr/local/lib/USBProxy/
vendorId = ffffffff
productId = ffffffff
DeviceProxy::nice = 50
cleaning up /tmp
removing 1
Made directory /tmp/gadget-BBuQUd for gadget
Printing Config data
    Strings: 3
        DeviceProxy: DeviceProxy_LibUSB
        DeviceProxy::nice: 50
        HostProxy: HostProxy_GadgetFS
    Vectors: 1
        Plugins:
            PacketFilter_StreamLog
    Pointer: 1
        PacketFilter_StreamLog::file: 0xb6d1ad10
|Connected to device: 0613:2043@04 TransAct - Ithaca USB Printer

Starting libusbEventLoop thread (26313) 
Error sending setup packet: Pipe error
Device: 12 01 00 02 00 00 00 40 13 06 43 20 01 01 01 02 03 01
  Manufacturer: TransAct
  Product:      Ithaca USB Printer
  Serial:       EPIC 430
    *Config(1): 09 02 37 00 02 01 00 c0 00
        Interface(0):
            *Alt(0): 09 04 00 00 02 ff 00 00 05
               Name: USB COM
                EP(84): 07 05 84 02 40 00 00
                EP(02): 07 05 02 02 40 00 00
        Interface(1):
            *Alt(0): 09 04 01 00 02 07 01 02 04
               Name: USB Prn
                EP(84): 07 05 84 02 40 00 00
                EP(02): 07 05 02 02 40 00 00
old bInterval: 00
calculated new bInterval: 00
old bInterval: 00
calculated new bInterval: 00
old bInterval: 00
calculated new bInterval: 00
old bInterval: 00
calculated new bInterval: 00

    00 00 00 00 09 02 37 00 02 01 00 c0 00 09 04 00 00 02 ff 00 00 05 07 05 84 02 40 00 00 07 05 02
    02 40 00 00 09 04 01 00 02 07 01 02 04 07 05 84 02 40 00 00 07 05 02 02 40 00 00 09 02 37 00 02
    01 00 c0 00 09 04 00 00 02 ff 00 00 05 07 05 84 02 40 00 00 07 05 02 02 40 00 00 09 04 01 00 02
    07 01 02 04 07 05 84 02 40 00 00 07 05 02 02 40 00 00 12 01 00 02 00 00 00 40 13 06 43 20 01 01
    01 02 03 01
searching in [/tmp/gadget-BBuQUd]
Starting setup writer thread (26316) for EP00.
Starting setup reader thread (26315) for EP00.
gadgetfs: event 1
============== Host Connect
gadgetfs: event 2
============== Host Disconnect
gadgetfs: event 1
============== Host Connect
[80 06 00 03 00 00 ff 00]
[80 06 00 03 00 00 04 00]: 04 03 09 04
[80 06 02 03 09 04 ff 00]
[80 06 02 03 09 04 26 00]: 
    26 03 49 00 74 00 68 00 61 00 63 00 61 00 20 00 55 00 53 00 42 00 20 00 50 00 72 00 69 00 6e 00
    74 00 65 00 72 00
[80 06 01 03 09 04 ff 00]
[80 06 01 03 09 04 12 00]: 12 03 54 00 72 00 61 00 6e 00 73 00 41 00 63 00 74 00
[80 06 03 03 09 04 ff 00]
[80 06 03 03 09 04 2c 00]: 
    2c 03 45 00 50 00 49 00 43 00 20 00 34 00 33 00 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00
[00 09 01 00 00 00 00 00]
HostProxy_GadgetFS::setConfig
Try to open /tmp/gadget-BBuQUd/ep4in
Opened EP84
Try to open /tmp/gadget-BBuQUd/ep2out
gadgetfs: max. packet size is 64 bytes for EP2
Opened EP02
Try to open /tmp/gadget-BBuQUd/ep4in
689 Fail on open EP84 16 Device or resource busy
Starting reader thread (26322) for EP84.
Starting reader thread (26320) for EP02.
Sending ACK
[80 06 05 03 09 04 ff 00]
Starting writer thread (26321) for EP02.
[80 06 05 03 09 04 10 00]: 10 03 55 00 53 00 42 00 20 00 43 00 4f 00 4d 00
[80 06 04 03 09 04 ff 00]
Starting writer thread (26323) for EP84.
[80 06 04 03 09 04 10 00]: 10 03 55 00 53 00 42 00 20 00 50 00 72 00 6e 00
gadgetfs: event 2
============== Host Disconnect
Finished writer thread (26321) for EP02.
Finished writer thread (26323) for EP84.
EP02 aio_cancel  rc = 1(AIO_NOTCANCELED), aio_error = 115 Operation now in progress
Finished reader thread (26320) for EP02.
Finished reader thread (26322) for EP84.
JOINABLE?: 1
JOIN READER: 4
gadgetfs: event 1
============== Host Connect
[80 06 03 03 09 04 ff 00]
[80 06 03 03 09 04 2c 00]: 
    2c 03 45 00 50 00 49 00 43 00 20 00 34 00 33 00 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00
[00 09 01 00 00 00 00 00]
HostProxy_GadgetFS::setConfig
Try to open /tmp/gadget-BBuQUd/ep4in
Opened EP84
Try to open /tmp/gadget-BBuQUd/ep2out

It hangs on int open_endpoint(__u8 epAddress, const char * gadget_filename) -> open() within src/Plugins/Hosts/GadgetFS_helpers.cpp

I also needed to remove workaround from Manager::stopEps exit(-1)

Leon90PL commented 3 years ago

I also noticed when host sends SET_CONFIGURATION, there is an error on reading from FD void HostProxy_GadgetFS::control_ack() read(p_device_file,0,0);

[00 09 01 00 00 00 00 00] LibUSB> 00 09 01 00 00 00 00 00 LibUSB< Sending ACK Read ACK error Invalid argument <- added log

another setup requests work fine OUT [01 0b 00 00 01 00 00 00] LibUSB> 01 0b 00 00 01 00 00 00 LibUSB< Sending ACK Read ACK result OK <- added log

MartinLoeper commented 3 years ago

Hey @Leon90PL, I am sorry that I cannot help you with this one atm. We support the rpi 4b only at Nesto and I lack the required low-level C skills to guess the root cause of your issue without having such a device. I hope to get some people involved into this project who know that stuff!