.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
IPcscProvider
interface 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:
IPcscProvider
InterfacePcsc
ClassPcsc<TIPcscProvider>
ClassWinSCard
Class
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:
SCardBeginTransaction
SCardCancel
SCardConnect
SCardControl
SCardDisconnect
SCardEndTransaction
SCardEstablishContext
SCardFreeMemory
SCardGetStatusChange
SCardIsValidContext
SCardListReaderGroups
SCardListReaders
SCardReconnect
SCardReleaseContext
SCardTransmit
Other methods:
AllocateIORequest
Allocates managed byte array which mapped to unmanaged
SCARD_IO_REQUEST
structure.AllocateReaderStates
Allocates managed byte array which mapped to unmanaged array of
SCARD_READERSTATE
structure.AllocateString
Allocates string in managed or unmanaged memory.
FreeString
Releases the unmanaged memory which allocated by
AllocateString
.ReadIORequest
Reads values from
SCARD_IO_REQUEST
which allocated byAllocateIORequest
method.ReadReaderState
Reads values from the specific index of the
SCARD_READERSTATE
array which allocated byAllocateReaderStates
method.SCardCtlCode
Gets reader action I/O control codes.
WriteIORequest
Writes values to
SCARD_IO_REQUEST
which allocated byAllocateIORequest
method.WriteReaderState
Writes values to the specific index of the
SCARD_READERSTATE
array which allocated byAllocateReaderStates
method.
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,
TIPcscProvider
can 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