Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LIBUSB_ERROR_TIMEOUT on first connect #206

Open
andrewbaxter opened this issue Aug 22, 2024 · 2 comments
Open

LIBUSB_ERROR_TIMEOUT on first connect #206

andrewbaxter opened this issue Aug 22, 2024 · 2 comments

Comments

@andrewbaxter
Copy link

Versions

  • smart card reader driver name and version

I'm not sure, AFAICT only the ccid plugin is installed. pn533_usb loaded itself but (as detailed later) I had to rmmod that.

  • pcsc-lite version
  • the output of the command /usr/sbin/pcscd --version
pcsc-lite version 2.2.3
Copyright (C) 1999-2002 by David Corcoran <[email protected]>.
Copyright (C) 2001-2024 by Ludovic Rousseau <[email protected]>.
Copyright (C) 2003-2004 by Damien Sauveron <[email protected]>.
Report bugs to <[email protected]>.
Enabled features: USB serial libudev polkit systemd Linux x86_64 ipcdir=/run/pcscd usbdropdir=/var/lib/pcsc/drivers serialconfdir=/etc/reader.conf.d
MAX_READERNAME: 128, PCSCLITE_MAX_READERS_CONTEXTS: 16

Platform

  • Operating system or GNU/Linux distribution name and version

NixOS unstable from the last couple days.

  • Smart card middleware name and version
  • Smart card reader manufacturer name and reader model name

ACR122U-A9, same as detected by pcscd, although the amazon listing was somewhat light on details (brand is "cyrank")

https://www.amazon.co.jp/gp/product/B0CNQNHBSY/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

  • Smart card name

N/A

Issue

The smartcard reader works fine, but when I boot with it attached I get either LIBUSB_ERROR_BUSY or LIBUSB_ERROR_TIMEOUT and it's unusable until I make additional manual changes.

There's two scenarios:

  1. I start the host with the reader attached, pcscd starts at boot (well, it's socket activated and a command that reads an nfc card runs at boot). The pn533_usb kernel module gets loaded automatically. pcscd starts with LIBUSB_ERROR_BUSY (during_pn533_usb.txt). Doing rmmod and restarting pcscd allows it to start and interact with the card fine (after_pn533_usb.txt).
  2. I start the host with the reader attached, pcscd setup as above, and the pn533_usb kernel module blacklisted. pcscd starts with LIBUSB_ERROR_TIMEOUT until I disconnect and reconnect the reader (physically), while pcscd is still running (reconnect.txt sorry, I did truncate this one but after it recognized the device). Stopping pcscd seems before reconnecting the reader doesn't do anything positive (the TIMEOUT error stays).

My current workaround is to let pn533_usb load then immediately rmmod it, which allows pcscd to start with no errors, but this is timing sensitive.

Log

I attached the logs above.

Thanks for all your work on this project, it's super cool and I've had almost no issues!

@LudovicRousseau
Copy link
Owner

From reconnect.txt I see:

00030486 [139916673252800] ccid_usb.c:1618:InterruptRead() after (0) (0)
00000005 [139916673252800] NotifySlotChange: 50 03 
00000004 [139916673252800] -> 000000 65 00 00 00 00 00 00 00 00 00 
00029515 [139916673252800] <- 000000 81 00 00 00 00 00 00 02 81 00 
00000006 [139916673252800] -> 000000 65 00 00 00 00 00 01 00 00 00 
00102874 [139916673252800] ccid_usb.c:1068:ReadUSB() read failed (1/11): LIBUSB_ERROR_TIMEOUT
00000035 [139916673252800] -> 000000 65 00 00 00 00 00 02 00 00 00 
00057229 [139916673252800] <- 000000 81 00 00 00 00 00 01 02 81 00 
00000023 [139916673252800] ccid_usb.c:1095:ReadUSB() Invalid frame detected
00102721 [139916673252800] ccid_usb.c:1068:ReadUSB() read failed (1/11): LIBUSB_ERROR_TIMEOUT

The reader answers the first command (frame 0). But failed to answer in time to the second command (frame 1).
But the answer arrives later after the driver sent the 3rd command (frame 3).
This generated the message Invalid frame detected.

Maybe the reader needs more time.

Try this patch:

diff --git a/src/ccid.c b/src/ccid.c
index fe08b87..1948080 100644
--- a/src/ccid.c
+++ b/src/ccid.c
@@ -81,6 +81,7 @@ int ccid_open_hack_pre(unsigned int reader_index)
 
 		case ElatecTWN4_CCID_CDC:
 		case ElatecTWN4_CCID:
+		case ACS_ACR122U:
 			/* Use a timeout of 1000 ms instead of 100 ms in
 			 * CmdGetSlotStatus() used by CreateChannelByNameOrChannel()
 			 * The reader answers after up to 1 s if no tag is present */
@@ -590,6 +591,7 @@ int ccid_open_hack_post(unsigned int reader_index)
 		case ElatecTWN4_CCID_CDC:
 		case ElatecTWN4_CCID:
 		case SCM_SCL011:
+		case ACS_ACR122U:
 			/* restore default timeout (modified in ccid_open_hack_pre()) */
 			ccid_descriptor->readTimeout = DEFAULT_COM_READ_TIMEOUT;
 			break;
diff --git a/src/ccid.h b/src/ccid.h
index 92415bf..e9c2a43 100644
--- a/src/ccid.h
+++ b/src/ccid.h
@@ -263,6 +263,7 @@ typedef struct
 #define ACS_ACR1552				0x072F2303
 #define KAPELSE_KAPLIN2			0x29470105
 #define KAPELSE_KAPECV			0x29470112
+#define ACS_ACR122U				0x072f2200
 
 #define VENDOR_KAPELSE 0x2947
 #define VENDOR_GEMALTO 0x08E6

@andrewbaxter
Copy link
Author

Oh awesome! I'll try that, it might take me a few days though. Thanks for looking at this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants