Bug 832983

Summary: PCSC Lite CCID causing ccid_usb.c:648:WriteUSB() write failed (1/10): -4 No such device
Product: [Fedora] Fedora Reporter: Manuel Bejarano <cicloide>
Component: libnfcAssignee: François Kooman <fkooman>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: unspecified    
Version: 17CC: fkooman, kalevlember, ludovic.rousseau+fedoraproject, ludovic.rousseau, rrelyea
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-08-09 23:30:42 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
pcscd log
none
pcscd log 2
none
pcscd log 3
none
libnfc usb enumeration patch none

Description Manuel Bejarano 2012-06-18 10:34:33 UTC
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 11:58:16 UTC
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 13:26:42 UTC
Created attachment 592642 [details]
pcscd log

Comment 3 Manuel Bejarano 2012-06-18 13:27:47 UTC
(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 14:24:20 UTC
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 14:49:34 UTC
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>
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 11:19:00 UTC
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 15:21:34 UTC
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 15:26:27 UTC
Sorry, wrong koji link above, it should be:

http://koji.fedoraproject.org/koji/buildinfo?buildID=327581

Comment 9 Manuel Bejarano 2012-07-04 19:42:59 UTC
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 20:49:55 UTC
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 21:43:31 UTC
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>
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>
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 21:44:16 UTC
Created attachment 596290 [details]
pcscd log 2

Comment 13 Ludovic Rousseau 2012-07-04 22:01:49 UTC
(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 12:45:45 UTC
(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 13:00:13 UTC
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 21:10:36 UTC
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 21:11:01 UTC
Created attachment 596505 [details]
pcscd log 3

Comment 18 Kalev Lember 2012-07-06 12:11:03 UTC
(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 21:01:21 UTC
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 22:54:23 UTC
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 22:55:50 UTC
Created attachment 600628 [details]
libnfc usb enumeration patch

Comment 22 Ludovic Rousseau 2012-07-27 08:20:49 UTC
reported to libnfc at https://code.google.com/p/libnfc/issues/detail?id=202

Comment 23 Kalev Lember 2012-07-30 11:43:48 UTC
Reassigning the ticket to libnfc.

Comment 24 Fedora Update System 2012-07-30 13:13:23 UTC
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 22:23:59 UTC
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 23:30:42 UTC
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.