.NET standard library for accessing PC/SC (Personal Computer/Smart Card) functions.
This library provides the generic way for accessing PC/SC functions, you can write your specific provider with
IPcscProviderinterface implementation.
- src/PcscDotNet
PcscDotNet library.
- tests/PcscDotNet.ConsoleTests
Console tests.
The implementations of PC/SC enumerations and structures and the declarations of PC/SC methods, both are referenced from Windows Kit, MSDN and pcsc-lite.
The main interfaces/classes:
IPcscProviderInterfacePcscClassPcsc<TIPcscProvider>ClassWinSCardClass
This interface declares the members that need to be implemented for accessing PC/SC functions.
These are the methods declared with the same name of PC/SC functions currently:
SCardBeginTransactionSCardCancelSCardConnectSCardControlSCardDisconnectSCardEndTransactionSCardEstablishContextSCardFreeMemorySCardGetStatusChangeSCardIsValidContextSCardListReaderGroupsSCardListReadersSCardReconnectSCardReleaseContextSCardTransmit
Other methods:
AllocateIORequestAllocates managed byte array which mapped to unmanaged
SCARD_IO_REQUESTstructure.AllocateReaderStatesAllocates managed byte array which mapped to unmanaged array of
SCARD_READERSTATEstructure.AllocateStringAllocates string in managed or unmanaged memory.
FreeStringReleases the unmanaged memory which allocated by
AllocateString.ReadIORequestReads values from
SCARD_IO_REQUESTwhich allocated byAllocateIORequestmethod.ReadReaderStateReads values from the specific index of the
SCARD_READERSTATEarray which allocated byAllocateReaderStatesmethod.SCardCtlCodeGets reader action I/O control codes.
WriteIORequestWrites values to
SCARD_IO_REQUESTwhich allocated byAllocateIORequestmethod.WriteReaderStateWrites values to the specific index of the
SCARD_READERSTATEarray which allocated byAllocateReaderStatesmethod.
If you want to implement your provider using WinSCard or pcsc-lite, see the table below, it shows the different definitions between platforms:
| Unmanaged Defined | * | WinSCard (Windows) |
pcsc-lite (OS X) |
pcsc-lite (Linux) |
|---|---|---|---|---|
SCARD_CTL_CODE(code) |
Define | 0x00310000 | (code << 2) |
0x42000000 + code |
0x42000000 + code |
| ANSI Characters | Encoding | System Locale | UTF-8 | UTF-8 |
| Unicode Characters | Encoding | Unicode | - | - |
SCARD_READERSTATE |
Pack | - | 1 |
- |
DWORD |
Size | 4 |
4 |
sizeof(void*) |
LONG |
Size | 4 |
4 |
sizeof(void*) |
SCARD_READERSTATE.rgbAtr |
Size | 36 |
33 |
33 |
SCARD_PROTOCOL_RAW |
Value | 0x00010000 |
0x04 |
0x04 |
This class is the start point for accessing PC/SC functions. You need to specify IPcscProvider instance to create Pcsc instance.
This class provides the static members with corresponding members in Pcsc class, using singleton instance of TIPcscProvider which implements IPcscProvider interface.
Most of time,
TIPcscProvidercan be used with singleton safely unless its members may be changed, e.g., the provider loads functions from different library dynamically.
This class implements IPcscProvider using WinSCard.dll of Windows environment (Unicode).
Archie Yang