A lot of readers connected to a computer...

I had planed to write about possible issues when connecting many readers and a new request "Connect 54 tokens in a usb hub" gives me the occasion to write this article.

pcsc-lite limitation

By default pcsc-lite is limited to 16 PC/SC readers. It is a known limitation, see "use a list instead of a fixed size array for 16 reader states".

It is easy to change the value of PCSCLITE_MAX_READERS_CONTEXTS from 16 to whatever you want and rebuild pcsc-lite.


libccid limitation

By default my CCID driver also is limited to 16 slots. It is a known limitation, see "use a list instead of a fixed size array for 16 reader states".

It is easy to change the value of CCID_DRIVER_MAX_READERS from 16 to whatever you want and rebuild libccid.


USB hardware limitation

The software limitations are easy to fix. Both pcsc-lite and libccid projects are Free Software for a good reason. You can adapt the software to your needs, within the respect of the software licence.

The problem now is that the hardware is also limited. Thanks to Harald Welte for mentioning this limitation to me. I am not a PC compatible hardware specialist but I found some interesting information.

From https://community.intel.com/t5/Embedded-Intel-Core-Processors/Hardware-limitations-on-USB-endpoints-XHCI/td-p/264556 "Hardware limitations on USB endpoints (XHCI)":

I have spoken to the Linux kernal developers and they state that "Intel Ivy Bridge system xhci host, the 64 endpoint is a hardware limitation."

From https://acroname.com/blog/how-many-usbs-can-i-connect-acroname "Why Can't I Connect More Usb 3.0 Devices To My System?":

The XHCI specification allows for a massive 7,906 enpoints! However, common implementations of the XHCI controllers impose their own limit on the total number of endpoints to 96. The most notorious of these Intel's series 8 architectures. This means that the maximum number of common devices which use 3 endpoints able to be attached to an Intel series 8 XHCI host controller is actually 96 endpoints / 3 endpoints per device = 32 devices. This is a known limitation of Intel-based XHCI controllers.

To make matters worse, USB 3.0 buses live in a strange dual existence with USB 2.0 devices. That is, they live in the similar yet separate tree architecture in parallel with USB 2.0 devices, but they share the same endpoints on XHCI controllers. USB 3.0 devices may implement endpoints on  both the USB 3.0 and 2.0 buses. This will even further reduce the number of devices which can be attached to a single XHCI host controller.

So the real problem is with the USB controller you use.

A CCID device uses 3 endpoints: Bulk IN, Bulk OUT and interrupt. If your xHCI controller can only handle 96 endpoints in total you can use a maximum of 96 / 3 = 32 readers. But I guess your computer do not have 32 USB ports available. So you will use one or more USB hubs. A USB hub consumes 4 or 5 endpoints for itself then you can use even less than 32 readers.

In fact, the limitation to 16 readers in pcsc-lite and libccid is reasonable compared to the hardware limitation of USB controllers.


Possible solutions

Special CCID reader

One possible solution is to use a CCID reader that can handle many smartcards. The CCID specification define a feature called "slot". A CCID smartcard reader can support up to 256 slots or 256 smartcards.

A CCID reader with support of a high number of slot exists. I plan to write about it in another blog article.

 

Enlarge your number of USB ports

Another solution to the hardware limitation may be to add PCI cards with 4 (or more) USB ports.

The description of such PCI card does not indicate the number of additional endpoints supported. So maybe you will find the controller supports even less than 96 endpoints.

 

Conclusion

I regularly get requests to support a "huge" number of smartcard readers. This article will serve as an answer now.

If you have other solutions please share them.