Bug 832983 - PCSC Lite CCID causing ccid_usb.c:648:WriteUSB() write failed (1/10): -4 No such device
PCSC Lite CCID causing ccid_usb.c:648:WriteUSB() write failed (1/10): -4 No s...
Status: CLOSED ERRATA
Product: Fedora
Classification: Fedora
Component: libnfc (Show other bugs)
17
x86_64 Linux
unspecified Severity low
: ---
: ---
Assigned To: François Kooman
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-06-18 06:34 EDT by Manuel Bejarano
Modified: 2012-08-09 19:30 EDT (History)
5 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2012-08-09 19:30:42 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
pcscd log (10.53 KB, text/plain)
2012-06-18 09:26 EDT, Manuel Bejarano
no flags Details
pcscd log 2 (10.07 KB, text/plain)
2012-07-04 17:44 EDT, Manuel Bejarano
no flags Details
pcscd log 3 (9.63 KB, text/plain)
2012-07-05 17:11 EDT, Manuel Bejarano
no flags Details
libnfc usb enumeration patch (339 bytes, patch)
2012-07-26 18:55 EDT, Manuel Bejarano
no flags Details | Diff

  None (edit)
Description Manuel Bejarano 2012-06-18 06:34:33 EDT
Description of problem:
NFC reader is not detected when using any of the libnfc-examples utils.

Version-Release number of selected component (if applicable):
pcsc-lite-ccid-1.4.6-1.fc17


Steps to Reproduce:
1. Install pcsc-lite, pcsc-lite-ccid, libusb, libnfc and libnfc-examples.
2. Plug a supported reader by CCID driver, in my case Touchatag.
3. Place any tag on the reader and execute "nfc-list".
  
Actual results:
No NFC device found.

Expected results:
ATR

Additional info:

The author seems to be aware of the problem:
http://comments.gmane.org/gmane.comp.lib.muscle/9037

As a workaround, downgrading to pcsc-lite-ccid-1.4.5-2.fc17 solves the problem.
Comment 1 Ludovic Rousseau 2012-06-18 07:58:16 EDT
I don't think your problem is related to the one reported by Martin Vogt in the email you reference.

Please follow http://pcsclite.alioth.debian.org/pcsclite.html#support to generate a log trace.
Comment 2 Manuel Bejarano 2012-06-18 09:26:42 EDT
Created attachment 592642 [details]
pcscd log
Comment 3 Manuel Bejarano 2012-06-18 09:27:47 EDT
(In reply to comment #1)
> I don't think your problem is related to the one reported by Martin Vogt in
> the email you reference.
> 
> Please follow http://pcsclite.alioth.debian.org/pcsclite.html#support to
> generate a log trace.

Please, let me know if you find out what is causing the problem or if you need further log traces.
Comment 4 Ludovic Rousseau 2012-06-18 10:24:20 EDT
I do not see any "ccid_usb.c:648:WriteUSB() write failed (1/10): -4 No such device" in your log.
I don't know from where you got the title of this bug report.

I do not see any thing strange from the pcscd log. I guess you can see the reader and the card ATR using the "pcsc_scan" command (from the pcsc-tools package).

It looks like the bug is in nfc-list.
Comment 5 Manuel Bejarano 2012-06-18 10:49:34 EDT
After connecting my reader and executing "service pcscd status", I get this message:

Redirecting to /bin/systemctl  status pcscd.service
pcscd.service - PC/SC Smart Card Daemon
	  Loaded: loaded (/usr/lib/systemd/system/pcscd.service; static)
	  Active: active (running) since Mon, 18 Jun 2012 16:34:19 +0200; 9min ago
	Main PID: 4307 (pcscd)
	  CGroup: name=systemd:/system/pcscd.service
		  └ 4307 /usr/sbin/pcscd --foreground --auto-exit

Jun 18 16:35:01 helena.lan pcscd[4307]: 00000000 ccid_usb.c:648:WriteUSB() write failed (1/9): -4 No such device
Jun 18 16:42:53 helena.lan pcscd[4307]: 99999999 ccid_usb.c:648:WriteUSB() write failed (1/10): -4 No such device
Jun 18 16:43:00 helena.lan pcscd[4307]: 07389131 ccid_usb.c:648:WriteUSB() write failed (1/11): -4 No such device
Jun 18 16:43:00 helena.lan pcscd[4307]: 00001350 ifdwrapper.c:341:IFDStatusICC() Card not transacted: 617
Jun 18 16:43:01 helena.lan pcscd[4307]: 01000330 ccid_usb.c:648:WriteUSB() write failed (1/11): -4 No such device
Jun 18 16:43:01 helena.lan pcscd[4307]: 00000032 ifdhandler.c:1129:IFDHPowerICC() PowerDown failed
Jun 18 16:43:01 helena.lan pcscd[4307]: 00000164 ccid_usb.c:648:WriteUSB() write failed (1/11): -4 No such device

And no matter what tools from the libnfc-examples package I use, I always get the "No NFC device found" message. The same tools are working when I downgrade to pcsc-lite-ccid-1.4.5-2.fc17 so I guess, the problem is not in the libnfc-examples tools. Executing pcsc_scan thows this at the output:

PC/SC device scanner
V 1.4.17 (c) 2001-2009, Ludovic Rousseau <ludovic.rousseau@free.fr>
Compiled with PC/SC lite version: 1.7.4
SCardEstablishContext: Service not available.

In the other hand, if I run pcscd as you suggested in order to generate a log trace and I execute pcsc_scan, I can see the ATR of the card but none of the libnfc tools are working, all of them keep trowing the "No NFC device found".

The same happens even if unplug/plug the reader.
Comment 6 Manuel Bejarano 2012-07-04 07:19:00 EDT
Hello Kalev,

Can you trigger a build of pcsc-lite-ccid-1.4.7-1.fc18 for Fedora 17?

This problem still persists with the latest package available in F17 repositories (pcsc-lite-ccid-1.4.6-1.fc17) and none of the tools built with libnfc seem to work right now.

Thanks.
Comment 7 Kalev Lember 2012-07-04 11:21:34 EDT
Manuel,

Can you please test if the rawhide build of pcsc-lite-ccid 1.4.7 fixes your issue? It should be a drop in replacement for the F17 pcsc-lite-ccid.

http://koji.fedoraproject.org/koji/buildinfo?buildID=325162
Comment 8 Kalev Lember 2012-07-04 11:26:27 EDT
Sorry, wrong koji link above, it should be:

http://koji.fedoraproject.org/koji/buildinfo?buildID=327581
Comment 9 Manuel Bejarano 2012-07-04 15:42:59 EDT
No, it does not work. This is strange, pcsc-lite-ccid-1.4.5-2.fc17 works as expected but my reader stops working when using any version >=1.4.6. 

When issuing any command with the problematic versions, the reader seems to work since the led becomes static but as I said before, it does not work with any tool built with libnfc.
Comment 10 Ludovic Rousseau 2012-07-04 16:49:55 EDT
In your comment #5 you show a NON working pcsc_scan. So the problem may not be only with libnfc.

Also you never took some time to generate a pcscd log trace as decribed in http://pcsclite.alioth.debian.org/pcsclite.html#support
Comment 11 Manuel Bejarano 2012-07-04 17:43:31 EDT
If I run pcsc_scan right after starting pcscd, this is what I get:



PC/SC device scanner
V 1.4.17 (c) 2001-2009, Ludovic Rousseau <ludovic.rousseau@free.fr>
Compiled with PC/SC lite version: 1.7.4
Scanning present readers...
0: ACS AET65 00 00

Wed Jul  4 23:26:41 2012
 Reader 0: ACS AET65 00 00
  Card state: Card inserted, 
  ATR: 3B BE 95 00 00 41 03 00 00 00 00 00 00 00 00 00 02 90 00

ATR: 3B BE 95 00 00 41 03 00 00 00 00 00 00 00 00 00 02 90 00
+ TS = 3B --> Direct Convention
+ T0 = BE, Y(1): 1011, K: 14 (historical bytes)
  TA(1) = 95 --> Fi=512, Di=16, 32 cycles/ETU
    125000 bits/s at 4 MHz, fMax for Fi = 5 MHz => 156250 bits/s
  TB(1) = 00 --> VPP is not electrically connected
  TD(1) = 00 --> Y(i+1) = 0000, Protocol T = 0 
-----
+ Historical bytes: 41 03 00 00 00 00 00 00 00 00 00 02 90 00
  Category indicator byte: 41 (proprietary format)

Possibly identified card (using /usr/share/pcsc/smartcard_list.txt):
3B BE 95 00 00 41 03 00 00 00 00 00 00 00 00 00 02 90 00
	touchatag SAM card



After stoping/starting pcscd again, the reader is not detected and this is the output:



PC/SC device scanner
V 1.4.17 (c) 2001-2009, Ludovic Rousseau <ludovic.rousseau@free.fr>
Compiled with PC/SC lite version: 1.7.4
SCardEstablishContext: Service not available.



I've attached anther log after running 'nfc-list' and 'nfc-anticol', where both of them did not detect the reader. I've been working with pcsc-lite and the ccid driver for some time now and this problem only appears with pcsc-lite-ccid version >=1.4.6. Downgrading to 1.4.5 solves all these issues. These are the packages that are causing the problems in my system right now:

pcsc-lite-1.8.3-1.fc17
pcsc-lite-libs-1.8.3-1.fc17
pcsc-lite-ccid-1.4.6-1.fc17
libnfc-1.4.2-2.fc17
Comment 12 Manuel Bejarano 2012-07-04 17:44:16 EDT
Created attachment 596290 [details]
pcscd log 2
Comment 13 Ludovic Rousseau 2012-07-04 18:01:49 EDT
(In reply to comment #11)
> After stoping/starting pcscd again, the reader is not detected and this is
> the output:

And what is the pcscd log in this specific case?

How do you stop/start pcscd?
Comment 14 Manuel Bejarano 2012-07-05 08:45:45 EDT
(In reply to comment #13)
> (In reply to comment #11)
> > After stoping/starting pcscd again, the reader is not detected and this is
> > the output:
> 
> And what is the pcscd log in this specific case?
> 

Sorry, my mistake, I was getting this when executing pcsc_scan without pcscd running.

> How do you stop/start pcscd?

# service pcscd start/stop

There is something curious, when executing 'service pcscd status', systemd reports that pcscd is running but I get this at the end of the output (and /var/log/messages):

utils.c:53:GetDaemonPid() Can't open /var/run/pcscd/pcscd.pid: No such file or directory
Comment 15 Ludovic Rousseau 2012-07-05 09:00:13 EDT
Please only run pcscd in debug mode for now:
sudo LIBCCID_ifdLogLevel=0x000F pcscd --foreground --debug --apdu

You will need to stop pcscd from systemd to avoid conflicts.
See http://ludovicrousseau.blogspot.com/2011/11/pcscd-auto-start-using-systemd.html
Comment 16 Manuel Bejarano 2012-07-05 17:10:36 EDT
Following your directions, I've stopped and killed all pcscd running processes before taking the new log that I've attached. It seems that everything is working fine but still the reader is not detected. There should be something new that changed from pcsc-lite-ccid 1.4.5 to 1.4.6 that is causing this problem or even pcsc-lite package.

The same packages were working fine with the last packages available before F17 was released. Could bug #831987 be related with this issue?
Comment 17 Manuel Bejarano 2012-07-05 17:11:01 EDT
Created attachment 596505 [details]
pcscd log 3
Comment 18 Kalev Lember 2012-07-06 08:11:03 EDT
(In reply to comment #16)
> Could bug #831987 be related with this issue?

No, this is unrelated. In rawhide (F18), libudev and systemd projects were merged together and bug #831987 is just a request to update the packaging for that.
Comment 19 Ludovic Rousseau 2012-07-26 17:01:21 EDT
Your reader is correctly detected with the name "ACS AET65 00 00".

The reader names have been reordered in CCID driver revision 1.4.6. The problem is that ACS is using the exact same USB PID (product ID) for different readers. So the reader name reported by pcsc-lite has changed for the same reader.

See also this bug "[#313729] libnfc broken with 1.4.7-1" https://alioth.debian.org/tracker/index.php?func=detail&aid=313729&group_id=30105&atid=410085

The bug is with libnfc (I think).

That do not explain the "write failed (1/9): -4 No such device" error message.
Comment 20 Manuel Bejarano 2012-07-26 18:54:23 EDT
Hi Ludovic,

You are right!

After checking the bug report you suggested, I added the name of my device as it is reported by pcsc-lite to the supported devices by libnfc using the patch that I've attached. That solves the issue and the reader operates correctly as it should.

I tried the patch against the last version available in Fedora repositories (1.4.2) so it should be integrated until a decision is taken regarding:

1. How pcsc-lite decides the device's name during enumeration for a device that share the USB ID. Note that my device (touchatag) was previously reported as "ACS ACR 38U-CCID" rather than "ACS AET65 00 00".
2. libnfc should incorporate these names associated to the same USB ID to avoid conflicts.

I don't know which option is the appropriate but somebody should file a bug against libnfc to warn them about it.

By the way, the "write failed (1/9): -4 No such device" error message is gone.

Thanks for your help guys!
Comment 21 Manuel Bejarano 2012-07-26 18:55:50 EDT
Created attachment 600628 [details]
libnfc usb enumeration patch
Comment 22 Ludovic Rousseau 2012-07-27 04:20:49 EDT
reported to libnfc at https://code.google.com/p/libnfc/issues/detail?id=202
Comment 23 Kalev Lember 2012-07-30 07:43:48 EDT
Reassigning the ticket to libnfc.
Comment 24 Fedora Update System 2012-07-30 09:13:23 EDT
libnfc-1.4.2-5.fc17 has been submitted as an update for Fedora 17.
https://admin.fedoraproject.org/updates/libnfc-1.4.2-5.fc17
Comment 25 Fedora Update System 2012-07-30 18:23:59 EDT
Package libnfc-1.4.2-5.fc17:
* should fix your issue,
* was pushed to the Fedora 17 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing libnfc-1.4.2-5.fc17'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2012-11283/libnfc-1.4.2-5.fc17
then log in and leave karma (feedback).
Comment 26 Fedora Update System 2012-08-09 19:30:42 EDT
libnfc-1.4.2-5.fc17 has been pushed to the Fedora 17 stable repository.  If problems still persist, please make note of it in this bug report.

Note You need to log in before you can comment on or make changes to this bug.