[Pcsclite-muscle] Multiple identical USB card readers

Ludovic Rousseau ludovic.rousseau at gmail.com
Sat Jun 7 09:06:54 PDT 2025


Le ven. 6 juin 2025 à 22:10, it at mrtv.lt <it at mrtv.lt> a écrit :
>
> Thanks for the explanation,
>
> 2025-06-05 22:57, Ludovic Rousseau rašė:
> > Le jeu. 5 juin 2025 à 16:41, it at mrtv.lt <it at mrtv.lt> a écrit :
> >> Hello,
> > Hello,
> >
> >> thank you for your reply. As far as I understand, the proposed solutions
> >> allow to identify which reader is which after the system has booted.
> >> However, reader identification is not my goal. The aim is to make sure
> >> that the reader numbers do not swap, so that a reader inserted in the
> >> appropriate slot is always identified, e.g. as “Reader 0”. These readers
> >> do not have serial numbers. But they could be “bound” using other unique
> >> attributes visible in the udevadm info (I noticed that the USB
> >> controller number changes, but the USB port number stays the same, which
> >> allows to build a udev rule). However, I don't know how to link these
> >> attributes to the reader enumeration mechanism used by pcscd.
> > The hotplug mechanism uses libudev (by default).
> What does this hotplug mechanism actually do with USB readers? If we
> swap the USB readers and then run pcscd
> --hotplug, we did not notice any effect. However, restarting pcscd
> changes the enumeration of the readers.
>   Is this hotplug mechanism applicable for USB readers? I found in the
> descriptions that it is for serial devices. How is it actually?

As documented --hotplug is only for serial readers.

libudev is used to be notify pccsd when a USB reader is connected or
disconnected.
The order the different USB devices are notified by libudev may be "random".
When pcscd is started it scans the USB bus. See the function HPScanUSB()
https://github.com/LudovicRousseau/PCSC/blob/master/src/hotplug_libudev.c#L565


> > The best I can propose is to provide a layer of indirection between a
> > stable name using the USB bus and port (retrieved using
> > SCARD_ATTR_CHANNEL_ID) and the PC/SC name.
> > For example "Reader 1 5" would be the reader connected on USB bus 1 and port 5.
> Perhaps that would solve my problem. Where and how to use this attribute?
> Could you point out an example?

In fact it is more complex. You will not get the port number but the
device index.
Example:
$ lsusb
[...]
Bus 001 Device 010: ID 08e6:3437 Gemalto (was Gemplus) GemPC Twin
SmartCard Reader
[...]

SCARD_ATTR_CHANNEL_ID will give your the bus number, here 001, and the
device index, here 010.

To know where physically the reader is connected you need to display
the USB tree or device hierarchy using:
$ lsusb -tvv
/:  Bus 001.Port 001: Dev 001, Class=root_hub, Driver=xhci_hcd/16p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub
    /sys/bus/usb/devices/usb1  /dev/bus/usb/001/001
    |__ Port 006: Dev 006, If 0, Class=Hub, Driver=hub/4p, 480M
        ID 058f:6254 Alcor Micro Corp. USB Hub
        /sys/bus/usb/devices/1-6  /dev/bus/usb/001/006
        |__ Port 002: Dev 010, If 0, Class=Chip/SmartCard, Driver=[none], 12M
            ID 08e6:3437 Gemalto (was Gemplus) GemPC Twin SmartCard Reader
            /sys/bus/usb/devices/1-6.2  /dev/bus/usb/001/010
[...]

The same reader Bus 001 and Device 010 is on port 002 of a hub itself
connected on port 006 of the root hub of bus 001.

Hope that helps.

Bye

--
 Dr. Ludovic Rousseau



More information about the pcsclite-muscle mailing list