[Pcsclite-muscle] Proposed update to SCardGetStatusChange()
Ludovic Rousseau
ludovic.rousseau at gmail.com
Sat Jun 29 03:17:33 PDT 2024
Hello,
SCardGetStatusChange() has a limitation that does not permit to detect
a reader addition or removal between 2 calls to
SCardGetStatusChange().
So if you run SCardGetStatusChange() in a loop you may miss some reader events.
I propose to fix this by using the high 16 bits of .dwEventState for
the special reader "\\?PnP?\Notification" to contain the number of
reader events.
See https://pcsclite.apdu.fr/api/group__API.html#ga33247d5d1257d59e55647c3bb717db24
for the API documentation.
The 1st time you call SCardGetStatusChange() the .dwEventState field
of "\\?PnP?\Notification" will be populated with the current number of
reader events.
The next time you call SCardGetStatusChange() the .dwEventState will
be checked and if a reader has been added or removed the call will
return immediately.
The proposed code is in the branch SCardGetStatusChange of the project
PCSC-debug
https://github.com/LudovicRousseau/PCSC-debug/tree/SCardGetStatusChange
I also provide a Unitary Test in
https://github.com/LudovicRousseau/PCSC-debug/blob/SCardGetStatusChange/UnitaryTests/SCardGetStatusChange/SCardGetStatusChange_PnP_Events.py
The test code will call SCardGetStatusChange(), wait for 5 seconds so
you can connect a new reader, call SCardGetStatusChange() again.
With the current implementation of pcsc-lite the second
SCardGetStatusChange() will timeout after 1 second (the reader
insertion event is lost).
With the proposed modification SCardGetStatusChange() will return immediately.
Windows uses a similar mechanism. But it uses the number of *readers*
instead of the number of reader *events*.
With my sample test code if you insert and remove a reader within the
5 seconds delay then the change will NOT be reported by Windows, but
it is reported by pcsc-lite.
Now I need your help to test my proposed code in your uses cases and
fix bugs before I include the changes in an official pcsc-lite
release.
Please git clone
https://github.com/LudovicRousseau/PCSC-debug/tree/SCardGetStatusChange,
install it and test it.
Report any issue or question you have.
Thanks
--
Dr. Ludovic Rousseau
More information about the pcsclite-muscle
mailing list