acshk / acsccid

acsccid is a PC/SC driver for Linux/Mac OS X and it supports ACS CCID smart card readers. This library provides a PC/SC IFD handler implementation and communicates with the readers through the PC/SC Lite resource manager (pcscd).
GNU Lesser General Public License v2.1
103 stars 19 forks source link

Slow card removal detection after loading authentication keys #29

Closed hinxx closed 1 year ago

hinxx commented 3 years ago

I'm working with ACR122U on Linux. I'm using a separate thread to detect reader and card arrival / removal. The timeout argument to the SCardGetStatusChange() is set to INFINITE.

When not performing any card access, I can see removal of the card being reported in less than 300 ms. As soon as I issue the command to load the keys the time increases to ~ 1.6 s. I'm looking at the timestamps in pcscd output.

Is this increase in card removal detection expected?

godfreychung commented 3 years ago

Are you using the command "Load Authentication Keys" with MIFARE Classic card?

hinxx commented 3 years ago

I think so. This is one of the cards I got with the reader, supposedly 1k MIFARE:

Card ATR: 3B 8F 80 01 80 4F 0C A0 00 00 03 06 03 00 01 00 00 00 00 6A
godfreychung commented 3 years ago

When the application sends APDU to the card, the reader uses communication timeout to detect card removal. Actually, the communication timeout is longer than the polling timeout.

hinxx commented 3 years ago

I managed to get an earlier card removal detection by issuing card ID read requests at a moderate rate (~200 ms) once the card is authenticated. This seems to tell the pcscd daemon (reader?) to issue a state change to the thread waiting such change. If there's a cleaner way, please, let me know.