Bug 1555264

Summary: pcscd needs to detach NFC reader device before claiming it
Product: [Fedora] Fedora Reporter: Till Maas <opensource>
Component: pcsc-liteAssignee: Bob Relyea <rrelyea>
Status: CLOSED EOL QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 27CC: hdegoede, klember, nmavrogi, opensource, rrelyea
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-11-30 20:24:31 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:

Description Till Maas 2018-03-14 11:04:01 UTC
Description of problem:
Recent versions of libusb have a new: libusb_set_auto_detach_kernel_driver() api which pcscd should call on the libusb_device_handle for the device before trying to claim interfaces, libusb will then automatically detech the kernel driver on claiming the interface (if necessary) and re-attach it on releasing the interface.

Version-Release number of selected component (if applicable):
pcsc-lite-1.8.22-3.fc27

How reproducible:
always

Steps to Reproduce:
1. attach USB NFC reader
2. 
3.

Actual results:
Mär 14 11:04:22 systemd[1]: Started PC/SC Smart Card Daemon.                                   
Mär 14 11:04:22 pcscd[4143]: 00000000 ccid_usb.c:649:OpenUSBByName() Can't claim interface 1/9: LIBUSB_ERROR_BUSY                                                                              
Mär 14 11:04:22 pcscd[4143]: 00000188 ifdhandler.c:150:CreateChannelByNameOrChannel() failed   
Mär 14 11:04:22 pcscd[4143]: 00000025 readerfactory.c:1105:RFInitializeReader() Open Port 0x200000 Failed (usb:072f/2200:libudev:0:/dev/bus/usb/001/009)                                       
Mär 14 11:04:22 pcscd[4143]: 00000005 readerfactory.c:376:RFAddReader() ACS ACR122U PICC Interface init failed.                                                                                
Mär 14 11:04:22 pcscd[4143]: 00000083 hotplug_libudev.c:523:HPAddDevice() Failed adding USB device: ACS ACR122U PICC Interface  

Expected results:
should work

Additional info:

it works after 
sudo sh -c "echo '1-1:1.0' > /sys/bus/usb/drivers/pn533_usb/unbind

This error appeared after the NCF reader driver was fixed, for details see:

https://bugzilla.redhat.com/show_bug.cgi?id=1514134#c15

Please forward this to upstream if there is a bug tracker. I will send an e-mail to pcsclite-muscle.debian.org to notify them.

Comment 1 Hans de Goede 2018-03-14 11:11:04 UTC
To be clear, the new libusb interface makes dealing with this *easier* libusb apps have always had to detach kernel drivers if one was attached to a device.

In the past apps had to manually call libusb_detach_kernel_driver() take note if a driver was actually detached and store that info and based on that info call libusb_attach_kernel_driver() on cleanup. On top apps also had to have special handling around calling libusb_reset() (if they use that) because that would cause the kernel driver to rebind.

A single libusb_set_auto_detach_kernel_driver() call makes the need for all this go away :)

Comment 2 Hans de Goede 2018-03-14 11:19:04 UTC
I just checked and libusb_detach_kernel_driver() is not that new anymore, it has been around for almost 5 years now:

https://github.com/libusb/libusb/commit/fc51f19341af70508b94c06ff763842b396ea72e

So I think it is ok to just use it unconditionally. Its introduction predates the introduction of the LIBUSB_API_VERSION define, so alternatively you could do:

#ifdef LIBUSB_API_VERSION
        libusb_set_auto_detach_kernel_driver(handle, 1);
#endif

To keep the code building with really old libusb1 versions.

Comment 3 Till Maas 2018-03-14 11:42:44 UTC
FYI: the mail to pcsclite-muscle.debian.org bounced:
    SMTP error from remote mail server after RCPT TO:<pcsclite-muscle.debian.org>:
    host mail.alioth.debian.org [5.153.231.21]: 550 Unrouteable address

Therefore upstream is not yet notified.

Comment 4 Nikos Mavrogiannopoulos 2018-03-14 16:46:50 UTC
The upstream address is: pcsclite-muscle.org
I'd appreciate if you forward this so that we don't act as MitM.

Comment 5 Till Maas 2018-03-14 17:04:58 UTC
Thank you Nikos, I re-sent the e-mail there.

Comment 6 Ben Cotton 2018-11-27 16:38:19 UTC
This message is a reminder that Fedora 27 is nearing its end of life.
On 2018-Nov-30  Fedora will stop maintaining and issuing updates for
Fedora 27. It is Fedora's policy to close all bug reports from releases
that are no longer maintained. At that time this bug will be closed as
EOL if it remains open with a Fedora  'version' of '27'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 27 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 7 Ben Cotton 2018-11-30 20:24:31 UTC
Fedora 27 changed to end-of-life (EOL) status on 2018-11-30. Fedora 27 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.