0

I have an app that uses a smart card reader. A user may have several identical readers, and their system names, as returned by SCardListReaders, differ in number suffix, for instance "OMNIKEY CardMan 5x21 0" and "OMNIKEY CardMan 5x21 1". User can set up the the reader for the app. If during work user puts the smart card in another reader the app will not react.

The problem is, I have reports that after the Windows restart the readers can be shuffled as well. The one that had "0" in the name before can now have "1". I have no influence on this. After the shuffle happens the user must choose the reader again in the app, and I want to fix this somehow so that user does not have to do anything.

First I was toying with SCardGetAttrib and SCARD_ATTR_VENDOR_IFD_SERIAL_NO, but this parameter does not return a unique string for every reader in the world. For instance it may return "12345678" for all readers of the same certain type.

I am now looking at SetupAPI function SetupDiGetDeviceRegistryProperty. I can list all USB devices, and parameters SPDRP_PHYSICAL_DEVICE_OBJECT_NAME and SPDRP_LOCATION_PATHS seem to be unique and I hope fixed in the system. If reader is not a USB device then I'll rely just on the name, as I am now. Problem is, I can't deduce from reader name which USB device I should be looking at. None of the SPDRP_ parameters will give me a reader name, and I need the name that I can give to SCardConnect.

How can I get from reader name to corresponding HDEVINFO that I can give to SetupDiGetDeviceRegistryProperty? Alternatively, is there another way to distinguish between smart card readers of the same type, which is reliable even after Windows restart?

Dialecticus
  • 16,400
  • 7
  • 43
  • 103
  • 2
    If the user has multiple readers, why limit the user to a specific reader? You can monitor the readers (see `SCardGetStatusChange()` and `SCardLocateCards/ByATR()`) to detect reader state changes and follow a card as it moves from one reader to another. Does `SCardGetReaderDeviceInstanceId()` allow you to differentiate readers? What about the device number provided by `SCARD_ATTR_CHANNEL_ID` from `SCardGetAttrib()`? – Remy Lebeau Sep 06 '16 at 23:15
  • Can't use `SCardLocateCards` because several cards of the same type can be inserted at the same time in different readers, but I am only interested in one of them. Can't use `SCardGetReaderDeviceInstanceId` because I have to support Windows XP (but Vista solution is also welcome). `SCARD_ATTR_CHANNEL_ID` gives the same value for all readers (0x200000). – Dialecticus Sep 07 '16 at 10:59

0 Answers0