Ticket #133 (new defect)

Opened 5 years ago

Last modified 4 years ago

Smartcard reader not accessible via USB 3.0

Reported by: hongquan Owned by:
Milestone: Component: libusb-1.0 Linux backend
Keywords: usb3.0, smartcard Cc:
Blocked By: Blocks:

Description

Hi,
I'm using CryptoStick? (USB security token with OpenPGP card) with OpenSC (it uses pcsc-lite and this in turn uses libusb).
I tried to use the stick on USB 3.0 port but not successful, while USB 2.0 is OK.

Attached is the log of libusb 1.0.9.

I use under Ubuntu 12.04.

Attachments

log_libusb.txt (57.9 KB) - added by sping 5 years ago.
Original log in uncompressed form
libusb_bulk-flag_changed_usb3.txt (97.3 KB) - added by stuge 5 years ago.
Uncompressed log after changing MAX_BULK_BUFFER_LENGTH
libusb_patched.tar.bz2 (4.2 KB) - added by hongquan 5 years ago.
libusb_patched_(updated).tar.bz2 (12.1 KB) - added by hongquan 5 years ago.

Download all attachments as: .zip

Change History

Changed 5 years ago by sping

Original log in uncompressed form

comment:1 Changed 5 years ago by hansdegoede

From the log:

libusb: 4.151209 debug [handle_bulk_completion] handling completion status -121 of bulk urb 1/5
libusb: 4.151221 debug [handle_bulk_completion] short transfer 39/16384 --> complete!
libusb: 4.151243 debug [discard_urbs] URB not found --> assuming ready to be reaped
libusb: 4.151267 debug [discard_urbs] URB not found --> assuming ready to be reaped
libusb: 4.151277 debug [discard_urbs] URB not found --> assuming ready to be reaped
libusb: 4.151285 debug [discard_urbs] URB not found --> assuming ready to be reaped

This means that the proper function of this device depends on the usbdevfs: BULK_CONTINUATION flag which atm does not work properly with XHCI controllers.

See the mail thread titled: "usbdevfs: BULK_CONTINUATION flag does not work with XHCI controller"

comment:2 Changed 5 years ago by xiaofan

The mail thread "usbdevfs: BULK_CONTINUATION flag does not work with XHCI controller" is here.
http://comments.gmane.org/gmane.comp.lib.libusbx.devel/469

The original mail thread for this ticket is here.
http://libusb.6.n5.nabble.com/Smartcard-reader-failed-on-USB-3-0-port-td5709817.html

comment:3 Changed 5 years ago by hansdegoede

hongquan, to confirm that this is the: "usbdevfs: BULK_CONTINUATION flag does not work with XHCI controller" issue, can you please download the libusb(x) sources tarbal, unpack and edit:
libusb/os/linux_usbfs.h
And change MAX_BULK_BUFFER_LENGTH to 131072

And then build and install that modified version, and see if that fixes things?

comment:4 follow-up: Changed 5 years ago by hongquan

It's even worse.
It made my app (OpenSC tool) hang and do nothing further.

comment:5 in reply to: ↑ 4 Changed 5 years ago by hansdegoede

Replying to hongquan:

It's even worse.
It made my app (OpenSC tool) hang and do nothing further.

So it does change the behavior, so we are likely getting somewhere, can you generate a new log with the patched libusb, to see where things go wrong now ?

comment:6 Changed 5 years ago by hongquan

Oh, this time, my problem is fixed (don't know why the last time failed). Please find my new log.

Changed 5 years ago by stuge

Uncompressed log after changing MAX_BULK_BUFFER_LENGTH

comment:7 Changed 5 years ago by hongquan

Oh, not really.
If I don't run

sudo LIBCCID_ifdLogLevel=0x000F pcscd --foreground --debug --apdu

(to get libusb & pcscd log), the problem is still as comment:4 (no log returned).

comment:8 Changed 5 years ago by hansdegoede

This sounds to me like in one scenario pcscd ends up using the old unpatched libraries, where as in the other scenario it is correctly using the patches libusb and/or pcscd is running as non root and thus failing to access the reader or some such.

comment:9 follow-up: Changed 5 years ago by hongquan

I just check that the pcscd is not needed to run as root, but must run in debug mode.
This reduced command still affective:

LIBCCID_ifdLogLevel=0x000F pcscd --foreground --debug

comment:10 in reply to: ↑ 9 ; follow-up: Changed 5 years ago by ludovicrousseau

Replying to hongquan:

I just check that the pcscd is not needed to run as root, but must run in debug mode.

I am surprised you do not need to run as root.

This reduced command still affective:

LIBCCID_ifdLogLevel=0x000F pcscd --foreground --debug

Please also check with:
$ pcscd --foreground --debug (so without LIBCCID_ifdLogLevel=)
$ pcscd --foreground
$ pcscd --debug

I suspect a timing issue. Using debug may change the timing and hide the bug.

comment:11 in reply to: ↑ 10 Changed 5 years ago by hongquan

Replying to ludovicrousseau:


Please also check with:
$ pcscd --foreground --debug (so without LIBCCID_ifdLogLevel=)
$ pcscd --foreground
$ pcscd --debug

I suspect a timing issue. Using debug may change the timing and hide the bug.

All 3 runs lead to "Transmit failed" in OpenSC.

Changed 5 years ago by hongquan

comment:12 follow-up: Changed 5 years ago by hongquan

Please find 3 logs corresponding to the 3 runs of pcscd.

comment:13 in reply to: ↑ 12 ; follow-up: Changed 5 years ago by ludovicrousseau

Replying to hongquan:

Please find 3 logs corresponding to the 3 runs of pcscd.

You get the same error as in the original bug report:
19008805 ccid_usb.c:677:ReadUSB() read failed (3/3): -7 Invalid argument

-7 is LIBUSB_ERROR_TIMEOUT

Why don't you have the libusb debug logs?
Have you rebuild libusb without logs?
Are you sure your rebuild has the MAX_BULK_BUFFER_LENGTH patch?

comment:14 in reply to: ↑ 13 Changed 5 years ago by hongquan

Replying to ludovicrousseau:

You get the same error as in the original bug report:
19008805 ccid_usb.c:677:ReadUSB() read failed (3/3): -7 Invalid argument

-7 is LIBUSB_ERROR_TIMEOUT

Why don't you have the libusb debug logs?
Have you rebuild libusb without logs?
Are you sure your rebuild has the MAX_BULK_BUFFER_LENGTH patch?

Very sorry for the mistake. The libusb.so symlink pointed to old version without my awareness.
Now I resent the 3 logs (from patched libusb).
Log 1 & Log2: OpenSC works.
Log 3: OpenSC stay standing.

Changed 5 years ago by hongquan

comment:15 Changed 4 years ago by stuge

  • Component changed from libusb-1.0 to libusb-1.0 Linux backend

comment:16 Changed 4 years ago by xiaofan

To the OP: this may or may not be a libusb-1.0 issue. It could well be a Linux xHCI driver problem. So you may want to try the later Linux kernel version to see if that helps.

For example, the following libusbx ticket with regard to USB 3.0 turns out to be a Linux xHCI driver problem. It may not be the same as your issue though.

Ref: https://github.com/libusbx/libusbx/issues/92
(Linux: gphoto2 works on USB 2.0 port but not USB 3.0 port)

comment:17 Changed 4 years ago by hongquan

I used newer kernel, 3.5.0, but this error still exists.
Changing MAX_BULK_BUFFER_LENGTH to 131072 works.

comment:18 Changed 4 years ago by xiaofan

Maybe you want to try out libusbx.git and later Linux kernel like 3.8.x to see if that helps.

comment:19 Changed 4 years ago by hjelmn

Can you try the latest 1.0.16 release candidate and let me know if it works. I brought over some of the max buffer len changes from libusbx.

Just grab the latest snapshot from here:
http://git.libusb.org/?p=libusb/libusb-darwin.git;a=summary;js=1

comment:20 Changed 4 years ago by hongquan

Hello,
The 1.0.16 get from that link does not work.

comment:21 Changed 4 years ago by hjelmn

By does not work do you mean the problem still exists?

You can download the latest release candidate from: http://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-1.0.16-rc6/libusb-1.0.16-rc6.tar.bz2/download

comment:22 Changed 4 years ago by hongquan

Yes, I still cannot get OpenSC to access to smartcard.

comment:23 Changed 4 years ago by xiaofan

Again this may well not be a libusb issue but rather Linux xHCI driver problem. Maybe you want to follow up in linux-usb mailing list. You need to try out the latest Linux kernel there.

Note: See TracTickets for help on using tickets.