SpringCard PC/SC API for .NET  18.10.10
Access PC/SC couplers and smart cards from .NET applications
SpringCard.PCSC.SCARD Class Reference

Static class that gives a direct access to PC/SC functions (SCard... provided by winscard.dll or libpcsclite) More...

Classes

class  NativeMethods
 Native methods. More...
 
struct  READERSTATE
 Internal structure used by GetStatusChange() (manipulate with care) More...
 

Static Public Member Functions

static IntPtr LoadLibrary_Unix (string fileName)
 
static void FreeLibrary_Unix (IntPtr handle)
 
static IntPtr GetProcAddress_Unix (IntPtr dllHandle, string name)
 
static IntPtr PCI_T0 ()
 .NET wrapper for PCI_T0 More...
 
static IntPtr PCI_T1 ()
 .NET wrapper for PCI_T1 More...
 
static IntPtr PCI_RAW ()
 .NET wrapper for PCI_RAW More...
 
static uint EstablishContext (uint dwScope, IntPtr nNotUsed1, IntPtr nNotUsed2, ref IntPtr phContext)
 .NET wrapper for SCardEstablishContext More...
 
static uint ReleaseContext (IntPtr Context)
 .NET wrapper for SCardReleaseContext
 
static uint GetStatusChange (IntPtr hContext, uint dwTimeout, READERSTATE[] rgReaderState, uint cReaders)
 .NET wrapper for SCardGetStatusChange More...
 
static uint Cancel (IntPtr hContext)
 .NET wrapper for SCardCancel
 
static uint Connect (IntPtr hContext, string cReaderName, uint dwShareMode, uint dwPrefProtocol, ref IntPtr phCard, ref uint ActiveProtocol)
 .NET wrapper for SCardConnect
 
static uint Reconnect (IntPtr hCard, uint dwShareMode, uint dwPrefProtocol, uint swInit, ref uint ActiveProtocol)
 .NET wrapper for SCardReconnect
 
static uint Disconnect (IntPtr hCard, uint Disposition)
 .NET wrapper for SCardDisconnect
 
static uint Status (IntPtr hCard, IntPtr mszReaderNames, ref uint pcchReaderLen, ref uint readerState, ref uint protocol, [In, Out] byte[] atr_bytes, ref uint atr_length)
 .NET wrapper for SCardStatus
 
static uint Transmit (IntPtr hCard, IntPtr pioSendPci, byte[] pbSendBuffer, uint cbSendLength, IntPtr pioRecvPci, [In, Out] byte[] pbRecvBuffer, [In, Out] ref uint pcbRecvLength)
 .NET wrapper for SCardTransmit
 
static uint GetAttrib (IntPtr hCard, uint dwAttrId, [In, Out] byte[] pbAttr, [In, Out] ref uint pcbAttrLength)
 .NET wrapper for SCardGetAttrib
 
static uint Control (IntPtr hCard, uint ctlCode, [In] byte[] pbSendBuffer, uint cbSendLength, [In, Out] byte[] pbRecvBuffer, uint RecvBuffsize, ref uint pcbRecvLength)
 .NET wrapper for SCardControl
 
static uint BeginTransaction (IntPtr hCard)
 .NET wrapper for SCardBeginTransaction
 
static uint EndTransaction (IntPtr hCard, uint Disposition)
 .NET wrapper for SCardEndTransaction
 
static uint ListCards (IntPtr phContext, byte[] pbAtr, byte[] rgguiInterfaces, uint cguidInterfaceCount, string mszCards, ref int pcchCards)
 .NET wrapper for SCardListCards (Windows only)
 
static uint IntroduceCardType (IntPtr phContext, string szCardName, byte[] pguidPrimaryProvider, byte[] rgguidInterfaces, uint dwInterfaceCount, byte[] atr, byte[] pbAtrMask, uint cbAtrLen)
 .NET wrapper for SCardIntroduceCardType (Windows only)
 
static uint SetCardTypeProviderName (IntPtr phContext, string szCardName, uint dwProviderId, string szProvider)
 .NET wrapper for SCardSetCardTypeProviderName (Windows only)
 
static string [] GetReaderList (IntPtr hContext, string Groups=null)
 .NET wrapper for SCardListReaders More...
 
static string [] GetReaderList (uint Scope, string Groups)
 .NET wrapper for SCardListReaders More...
 
static string [] GetReaderList ()
 .NET wrapper for SCardListReaders More...
 
static string [] ListReaders (IntPtr hContext, string Groups=null)
 .NET wrapper for SCardListReaders More...
 
static string [] ListReaders (uint Scope, string Groups)
 .NET wrapper for SCardListReaders More...
 
static string [] ListReaders ()
 .NET wrapper for SCardListReaders More...
 
static uint ListReadersWithDeviceInstanceId (IntPtr context, string groups, string readers, ref uint size)
 .NET wrapper for SCardListReadersWithDeviceInstanceId (Windows only)
 
static string [] GetReaderListWithDeviceInstanceId (IntPtr hContext, string InstanceId)
 .NET wrapper for SCardListReadersWithDeviceInstanceId (Windows only)
 
static string [] GetReaderListWithDeviceInstanceId (uint Scope, string InstanceId)
 
static string [] GetReaderListWithDeviceInstanceId (string InstanceId)
 
static string ErrorCodeToString (uint code)
 Translate a PC/SC error code (return value of any SCard... function) into its constant name.
 
static string ErrorToString (uint code)
 Translate a PC/SC error code into a user-readable string.
 
static string ErrorToMessage (uint code)
 Translate a PC/SC error code into a user-readable string, including the error code itself.
 
static string ReaderStatusToString (uint state)
 Translate a PC/SC reader status into a comma-separated set of constant names.
 
static string CardProtocolToString (uint protocol)
 Translate a PC/SC protocol into its text explanation.
 
static string CardShareModeToString (uint share_mode)
 Translate a PC/SC share mode into its text explanation.
 
static string CardStatusWordsToString (ushort SW)
 Translate a smart card status word into a text explanation.
 
static string CardStatusWordsToString (byte SW1, byte SW2)
 Translate a smart card status word into a text explanation.
 

Public Attributes

const uint SCOPE_USER = 0
 dwScope parameter for EstablishContext(): scope is user space. Same as SCARD_SCOPE_USER in winscard
 
const uint SCOPE_TERMINAL = 1
 dwScope parameter for EstablishContext(): scope is the terminal. Same as SCARD_SCOPE_TERMINAL in winscard
 
const uint SCOPE_SYSTEM = 2
 dwScope parameter for EstablishContext(): scope is system. Same as SCARD_SCOPE_SYSTEM in winscard
 
const string ALL_READERS = "SCard$AllReaders\0\0"
 groups parameter for ListReaders(): list all readers. Same as SCARD_ALL_READERS in winscard
 
const string DEFAULT_READERS = "SCard$DefaultReaders\0\0"
 groups parameter for ListReaders(): list the readers that are not in a specific group. Same as SCARD_DEFAULT_READERS in winscard
 
const string LOCAL_READERS = "SCard$LocalReaders\0\0"
 groups parameter for ListReaders(): list local readers (deprecated and unused). Same as SCARD_LOCAL_READERS in winscard
 
const string SYSTEM_READERS = "SCard$SystemReaders\0\0"
 groups parameter for ListReaders(): list system readers (deprecated and unused). Same as SCARD_SYSTEM_READERS in winscard
 
const uint SHARE_EXCLUSIVE = 1
 share mode parameter for Connect(): take an exclusive access to the card. Same as SCARD_SHARE_EXCLUSIVE in winscard
 
const uint SHARE_SHARED = 2
 share mode parameter for Connect(): accept to share the access to the card. Same as SCARD_SHARE_SHARED in winscard
 
const uint SHARE_DIRECT = 3
 share mode parameter for Connect(): take a direct access to the reader (even if there is no card in the reader). Same as SCARD_SHARE_DIRECT in winscard
 
const uint PROTOCOL_NONE = 0
 protocol parameter for Connect() and Status(): no active protocol (no card, direct access to the reader). Same as SCARD_PROTOCOL_UNSET in winscard
 
const uint PROTOCOL_T0 = 1
 protocol parameter for Connect() and Status(): protocol is T=0. Same as SCARD_PROTOCOL_T0 in winscard
 
const uint PROTOCOL_T1 = 2
 protocol parameter for Connect() and Status(): protocol is T=1. Same as SCARD_PROTOCOL_T1 in winscard
 
const uint PROTOCOL_RAW = 4
 protocol parameter for Connect() and Status(): protocol is RAW. Same as SCARD_PROTOCOL_RAW in winscard
 
const uint LEAVE_CARD = 0
 disposition parameter for Disconnect() and Reconnect(): leave the card as is. Same as SCARD_LEAVE_CARD in winscard
 
const uint RESET_CARD = 1
 disposition parameter for Disconnect() and Reconnect(): warm reset the card. Same as SCARD_RESET_CARD in winscard
 
const uint UNPOWER_CARD = 2
 disposition parameter for Disconnect() and Reconnect(): power down the card. Same as SCARD_UNPOWER_CARD in winscard
 
const uint EJECT_CARD = 3
 disposition parameter for Disconnect() and Reconnect(): power down the card, and eject it in case of a motorized reader. Same as SCARD_EJECT_CARD in winscard
 
const uint STATE_UNAWARE = 0x00000000
 state flags for READERSTATE in GetStatusChange(): no flag set. Same as SCARD_STATE_UNAWARE in winscard
 
const uint STATE_IGNORE = 0x00000001
 state flags for READERSTATE in GetStatusChange(): no information required. Same as SCARD_STATE_IGNORE in winscard
 
const uint STATE_CHANGED = 0x00000002
 state flags for READERSTATE in GetStatusChange(): the reader's state has changed since the last call. Same as SCARD_STATE_CHANGED in winscard
 
const uint STATE_UNKNOWN = 0x00000004
 state flags for READERSTATE in GetStatusChange(): the reader does not exist. Same as SCARD_STATE_UNKNOWN in winscard
 
const uint STATE_UNAVAILABLE = 0x00000008
 state flags for READERSTATE in GetStatusChange(): the reader's state is not available. Same as SCARD_STATE_UNAVAILABLE in winscard
 
const uint STATE_EMPTY = 0x00000010
 state flags for READERSTATE in GetStatusChange(): there is no card in the reader. Same as SCARD_STATE_EMPTY in winscard
 
const uint STATE_PRESENT = 0x00000020
 state flags for READERSTATE in GetStatusChange(): there is a card in the reader. Same as SCARD_STATE_PRESENT in winscard
 
const uint STATE_ATRMATCH = 0x00000040
 
const uint STATE_EXCLUSIVE = 0x00000080
 state flags for READERSTATE in GetStatusChange(): the card in the reader is reserved for exclusive use by an application. Same as SCARD_STATE_EXCLUSIVE in winscard
 
const uint STATE_INUSE = 0x00000100
 state flags for READERSTATE in GetStatusChange(): the card in the reader is connected by an application. Same as SCARD_STATE_INUSE in winscard
 
const uint STATE_MUTE = 0x00000200
 state flags for READERSTATE in GetStatusChange(): the card in the reader is unresponsive. Same as SCARD_STATE_MUTE in winscard
 
const uint STATE_UNPOWERED = 0x00000400
 state flags for READERSTATE in GetStatusChange(): the card in the reader has been powered down. Same as SCARD_STATE_UNPOWERED in winscard
 
const uint IOCTL_CSB6_PCSC_ESCAPE = 0x00312000
 
const uint IOCTL_MS_CCID_ESCAPE = 0x003136B0
 
const uint IOCTL_PCSCLITE_ESCAPE = 0x42000000 + 1
 
const uint ATTR_ATR_STRING = 0x00090303
 
const uint ATTR_CHANNEL_ID = 0x00020110
 
const uint ATTR_CHARACTERISTICS = 0x00060150
 
const uint ATTR_CURRENT_BWT = 0x00080209
 
const uint ATTR_CURRENT_CLK = 0x00080202
 
const uint ATTR_CURRENT_CWT = 0x0008020A
 
const uint ATTR_CURRENT_D = 0x00080204
 
const uint ATTR_CURRENT_EBC_ENCODING = 0x0008020B
 
const uint ATTR_CURRENT_F = 0x00080203
 
const uint ATTR_CURRENT_IFSC = 0x00080207
 
const uint ATTR_CURRENT_IFSD = 0x00080208
 
const uint ATTR_CURRENT_N = 0x00080205
 
const uint ATTR_CURRENT_PROTOCOL_TYPE = 0x00080201
 
const uint ATTR_CURRENT_W = 0x00080206
 
const uint ATTR_DEFAULT_CLK = 0x00030121
 
const uint ATTR_DEFAULT_DATA_RATE = 0x00030123
 
const uint ATTR_DEVICE_FRIENDLY_NAME = 0x7FFF0003
 
const uint ATTR_DEVICE_IN_USE = 0x7FFF0002
 
const uint ATTR_DEVICE_SYSTEM_NAME = 0x7FFF0003
 
const uint ATTR_DEVICE_UNIT = 0x7FFF0001
 
const uint ATTR_ICC_INTERFACE_STATUS = 0x00090301
 
const uint ATTR_ICC_PRESENCE = 0x00090300
 
const uint ATTR_ICC_TYPE_PER_ATR = 0x00090304
 
const uint ATTR_MAX_CLK = 0x00030122
 
const uint ATTR_MAX_DATA_RATE = 0x00030124
 
const uint ATTR_MAX_IFSD = 0x00030125
 
const uint ATTR_POWER_MGMT_SUPPORT = 0x00040131
 
const uint ATTR_PROTOCOL_TYPES = 0x00030126
 
const uint ATTR_VENDOR_IFD_SERIAL_NO = 0x00010103
 
const uint ATTR_VENDOR_IFD_TYPE = 0x00010101
 
const uint ATTR_VENDOR_IFD_VERSION = 0x00010102
 
const uint ATTR_VENDOR_NAME = 0x00010100
 
const uint S_SUCCESS = 0x00000000
 
const uint F_INTERNAL_ERROR = 0x80100001
 
const uint E_CANCELLED = 0x80100002
 
const uint E_INVALID_HANDLE = 0x80100003
 
const uint E_INVALID_PARAMETER = 0x80100004
 
const uint E_INVALID_TARGET = 0x80100005
 
const uint E_NO_MEMORY = 0x80100006
 
const uint F_WAITED_TOO_LONG = 0x80100007
 
const uint E_INSUFFICIENT_BUFFER = 0x80100008
 
const uint E_UNKNOWN_READER = 0x80100009
 
const uint E_TIMEOUT = 0x8010000A
 
const uint E_SHARING_VIOLATION = 0x8010000B
 
const uint E_NO_SMARTCARD = 0x8010000C
 
const uint E_UNKNOWN_CARD = 0x8010000D
 
const uint E_CANT_DISPOSE = 0x8010000E
 
const uint E_PROTO_MISMATCH = 0x8010000F
 
const uint E_NOT_READY = 0x80100010
 
const uint E_INVALID_VALUE = 0x80100011
 
const uint E_SYSTEM_CANCELLED = 0x80100012
 
const uint F_COMM_ERROR = 0x80100013
 
const uint F_UNKNOWN_ERROR = 0x80100014
 
const uint E_INVALID_ATR = 0x80100015
 
const uint E_NOT_TRANSACTED = 0x80100016
 
const uint E_READER_UNAVAILABLE = 0x80100017
 
const uint P_SHUTDOWN = 0x80100018
 
const uint E_PCI_TOO_SMALL = 0x80100019
 
const uint E_READER_UNSUPPORTED = 0x8010001A
 
const uint E_DUPLICATE_READER = 0x8010001B
 
const uint E_CARD_UNSUPPORTED = 0x8010001C
 
const uint E_NO_SERVICE = 0x8010001D
 
const uint E_SERVICE_STOPPED = 0x8010001E
 
const uint E_UNEXPECTED = 0x8010001F
 
const uint E_ICC_INSTALLATION = 0x80100020
 
const uint E_ICC_CREATEORDER = 0x80100021
 
const uint E_UNSUPPORTED_FEATURE = 0x80100022
 
const uint E_DIR_NOT_FOUND = 0x80100023
 
const uint E_FILE_NOT_FOUND = 0x80100024
 
const uint E_NO_DIR = 0x80100025
 
const uint E_NO_FILE = 0x80100026
 
const uint E_NO_ACCESS = 0x80100027
 
const uint E_WRITE_TOO_MANY = 0x80100028
 
const uint E_BAD_SEEK = 0x80100029
 
const uint E_INVALID_CHV = 0x8010002A
 
const uint E_UNKNOWN_RES_MNG = 0x8010002B
 
const uint E_NO_SUCH_CERTIFICATE = 0x8010002C
 
const uint E_CERTIFICATE_UNAVAILABLE = 0x8010002D
 
const uint E_NO_READERS_AVAILABLE = 0x8010002E
 
const uint E_COMM_DATA_LOST = 0x8010002F
 
const uint E_NO_KEY_CONTAINER = 0x80100030
 
const uint W_UNSUPPORTED_CARD = 0x80100065
 
const uint W_UNRESPONSIVE_CARD = 0x80100066
 
const uint W_UNPOWERED_CARD = 0x80100067
 
const uint W_RESET_CARD = 0x80100068
 
const uint W_REMOVED_CARD = 0x80100069
 
const uint W_SECURITY_VIOLATION = 0x8010006A
 
const uint W_WRONG_CHV = 0x8010006B
 
const uint W_CHV_BLOCKED = 0x8010006C
 
const uint W_EOF = 0x8010006D
 
const uint W_CANCELLED_BY_USER = 0x8010006E
 
const uint W_CARD_NOT_AUTHENTICATED = 0x8010006F
 

Static Public Attributes

static bool UseLogger = false
 Tell whether the PC/SC library provides trace/debug messages using SpringCard.LibCs.Logger class. Set to false to disable. More...
 

Properties

static string [] Readers [get]
 Alias for ListReaders()
 

Detailed Description

Static class that gives a direct access to PC/SC functions (SCard... provided by winscard.dll or libpcsclite)

Member Function Documentation

◆ EstablishContext()

static uint SpringCard.PCSC.SCARD.EstablishContext ( uint  dwScope,
IntPtr  nNotUsed1,
IntPtr  nNotUsed2,
ref IntPtr  phContext 
)
static

.NET wrapper for SCardEstablishContext

The application shall open a resource manager context for every thread, and must call ReleaseContext for all open contexts when exiting.

◆ GetReaderList() [1/3]

static string [] SpringCard.PCSC.SCARD.GetReaderList ( IntPtr  hContext,
string  Groups = null 
)
static

.NET wrapper for SCardListReaders

◆ GetReaderList() [2/3]

static string [] SpringCard.PCSC.SCARD.GetReaderList ( uint  Scope,
string  Groups 
)
static

.NET wrapper for SCardListReaders

◆ GetReaderList() [3/3]

static string [] SpringCard.PCSC.SCARD.GetReaderList ( )
static

.NET wrapper for SCardListReaders

◆ GetStatusChange()

static uint SpringCard.PCSC.SCARD.GetStatusChange ( IntPtr  hContext,
uint  dwTimeout,
READERSTATE []  rgReaderState,
uint  cReaders 
)
static

.NET wrapper for SCardGetStatusChange

This function blocks the execution of the thread until the state of a reader changes, or a timeout occurs.

◆ ListReaders() [1/3]

static string [] SpringCard.PCSC.SCARD.ListReaders ( IntPtr  hContext,
string  Groups = null 
)
static

.NET wrapper for SCardListReaders

A valid hContext must be supplied - see EstablishContext()

◆ ListReaders() [2/3]

static string [] SpringCard.PCSC.SCARD.ListReaders ( uint  Scope,
string  Groups 
)
static

.NET wrapper for SCardListReaders

A temporary context is created in the specified Scope

◆ ListReaders() [3/3]

static string [] SpringCard.PCSC.SCARD.ListReaders ( )
static

.NET wrapper for SCardListReaders

A temporary context is created in the system scope

◆ PCI_RAW()

static IntPtr SpringCard.PCSC.SCARD.PCI_RAW ( )
static

.NET wrapper for PCI_RAW

Use this constant with Transmit() if card protocol is RAW

◆ PCI_T0()

static IntPtr SpringCard.PCSC.SCARD.PCI_T0 ( )
static

.NET wrapper for PCI_T0

Use this constant with Transmit() if card protocol is T=0

◆ PCI_T1()

static IntPtr SpringCard.PCSC.SCARD.PCI_T1 ( )
static

.NET wrapper for PCI_T1

Use this constant with Transmit() if card protocol is T=1

Member Data Documentation

◆ UseLogger

bool SpringCard.PCSC.SCARD.UseLogger = false
static

Tell whether the PC/SC library provides trace/debug messages using SpringCard.LibCs.Logger class. Set to false to disable.

Warning
Sensitive content may be leaked if the Debug level is enabled in SpringCard.LibCs.Logger.

The documentation for this class was generated from the following files: