Accessing a lot of smart cards?

In "A lot of readers connected to a computer..." I presented a problem you can have when accessing many USB smart card readers.

It is possible to access a lot of smart cards with a limited number of readers.


Multislots readers

As I explained in the previous article:

One possible solution is to use a CCID reader that can handle many smart cards. The CCID specification defines a feature called "slot". A CCID smart card reader can support up to 256 slots or 256 smart cards.

The number of slots of a CCID reader is available in the bMaxSlotIndex field. See "CCID descriptor statistics: bMaxSlotIndex". Many readers, 92.91% (in 2013 when I wrote the article), only have one slot.

Readers may have 2 or more slots but not all the slots can be used at the same time. The maximum number of slots that are usable at the same time is available in the bMaxCCIDBusySlots field. See "CCID descriptor statistics: bMaxCCIDBusySlots". And 98.82% of the readers (again in 2013) are able to handle only 1 slot at a time.

As of today, only 9 readers (1.53%) have bMaxCCIDBusySlots≥2 so can use 2 or more slots at the same time. But the situation changed since 2013.


8 slots

A smart card reader with 8 slots already exists. It is the sysmoOCTSIM I presented in "sysmoOCTSIM: 8 slots reader". This reader has 8 slots. So you can access 8 smart cards with the same USB device (using only 3 USB endpoints). And more importantly, you can access all the 8 slots at the same time.

192 slots?

Sysmocom also has the project to build the sysmoSIMBANK-96 and sysmoSIMBANK-192 units with 96 and 192 slots, respectively.

One limitation is that you have to use Mini-SIM (2FF) format smart cards. But if you plan to use as many as 192 smart cards maybe you can use the adequate form factor for the smart card.


Multi access performances

Since I have a sysmoOCTSIM reader I wanted to make some performance tests using my usim_read.py Python program I presented in "Reading a SIM card phone book in Python". One benefit of using Python is that the PC/SC Python wrapper is available for GNU/Linux, macOS and Windows. So no need to port or recompile a program.

I wanted to make tests on the reference platform for PC/SC and CCID i.e. Windows. I connect the sysmoOCTSIM reader and... nothing. The Windows CCID driver does not recognize the reader, not even the first slot. I am (again) very disappointed by Windows.

So I will use a Debian GNU/Linux system.

3 independent readers

First I start with 3 independent "normal" USB readers:

With the Cherry reader I get:

$ time ./usim_read.py 1
Available readers:
- Gemalto PC Twin Reader 00 00
- Cherry GmbH CHERRY SECURE BOARD 1.0 [CHERRY SECURE BOARD 1.0] (00000002JS0405948M3DOGKTHA) 01 00
- Gemalto PC Twin Reader 02 00
Using: Cherry GmbH CHERRY SECURE BOARD 1.0 [CHERRY SECURE BOARD 1.0] (00000002JS0405948M3DOGKTHA) 01 00
Select MF
Select DF Telecom
Select EF ADN
Get Response
1: Name: Gilles Georges Aime, phone: 1216240521
2: Name: Lucienne Aimee Bert, phone: 6613167868
[...]
249: Name: Loup Regis Laurent., phone: 6056648470

real	0m6,068s
user	0m0,103s
sys	0m0,038s

A total time of 6.068 seconds.

With the Gemalto reader I get:

$ time ./usim_read.py 0
Available readers:
- Gemalto PC Twin Reader 00 00
- Cherry GmbH CHERRY SECURE BOARD 1.0 [CHERRY SECURE BOARD 1.0] (00000002JS0405948M3DOGKTHA) 01 00
- Gemalto PC Twin Reader 02 00
Using: Gemalto PC Twin Reader 00 00
Select MF
Select DF Telecom
Select EF ADN
Get Response
1: Name: Juliette Claire Fra, phone: 0574007144
2: Name: Luc Nicolas Regis.., phone: 3864760137
[...]
249: Name: Solange Marguerite , phone: 0569846150

real	0m5,564s
user	0m0,093s
sys	0m0,046s

A total time of 5.564 seconds.

The Cherry reader is a bit slower (0.5 s) than the Gemalto reader. This can be explained by the different clock frequencies.
The Gemalto default clock is: dwDefaultClock: 4.000 MHz
The Cherry default clock is: dwDefaultClock: 3.685 MHz

From the CCID driver logs you can see the different communication speeds used.

For the Gemalto reader we have:

00000012 [140389477558016] ifdhandler.c:847:IFDHSetProtocolParameters() Set speed to 250000 bauds

For the Cherry reader we have:

00000012 [140389477558016] ifdhandler.c:847:IFDHSetProtocolParameters() Set speed to 230312 bauds

A difference of 8.5% in clock speed generates a difference of 8.5% in communication baud rate, and a difference of ~9% in execution time.

The Cherry reader has a maximum clock speed of: dwMaximumClock: 14.320 MHz
The Gemalto reader has a maximum clock speed of: dwMaximumClock: 4.000 MHz

So the Cherry reader could be much faster. But the CCID driver does not yet support changing the clock speed. If you are interested by this change please contact me.


Mixing accesses

We now need to be able to run the usim_read.py program in parallel on the 3 readers. One very easy way to do that is to use the make command with this Makefile file:

CMD=./usim_read.py

all: 0.test 1.test 2.test

%.test:
	${CMD} $(@:.test=)

Calling make 0.test will run ./usim_read 0. Calling make will run the 3 targets 0.test, 1.test and 2.test.

By default make will run the 3 targets sequentially. But if you use make -j the 3 executions will be started in parallel.

 

Results

number of readers sequential exe parallel exe
1 5.564s 5.564s
2 11.099s 5.533s
3 17.083s 6.049s

 

As expected the time grows linearly in the sequential execution, but stays constant in the parallel execution.


sysmoOCTSIM

My CCID driver for Unix do support multi-slot readers. But only one slot can be used at the same time. It is a limitation of the driver.

Supporting accesses to 2 or more slots in parallel would imply a change from synchronous USB communication to asynchronous USB communication. That is a possible change but not an easy one.


Results

number of slots sequential exe parallel exe
1 5.126s 5.126s
2 10.273s 10.030s
3 15.321s 14.944s

The performance is a bit better on the sysmoOCTSIM reader (5.126s) than on the Gemalto reader (5.564s). I guess the reader is using a slightly higher clock frequency.

You may note that in the case of parallel execution we have a linear growth. As I explained before only one slot can be used at the same time. So pcsc-lite (the PC/SC resource manager) has to serialize the accesses to the different slots from the different executions.

The parallel execution is a bit more efficient than the sequential execution because part of the execution can be executed in parallel. But not so much.

 

Improving the CCID driver

It is possible to access all the slots at the same time for the sysmoOCTSIM reader. But the CCID driver needs to be updated.

If you need to access lots of SIM format smart card at the same time please contact me.


Conclusion

Connecting many smart cards to a single computer is possible.

You can connect many readers but the USB architecture may limit you. Or you can use one or more multi-slot readers to limit the requirements on the USB bus.