Show / Hide Table of Contents

Interface IPrimitives

Interface to be implemented by all PC/SC API wrappers.

Namespace: WSCT.Wrapper
Assembly: WSCT.dll
Syntax
public interface IPrimitives

Properties

| Improve this Doc View Source

AutoAllocate

Value used by PC/SC API to ask for auto allocation.

Declaration
uint AutoAllocate { get; }
Property Value
Type Description
System.UInt32
| Improve this Doc View Source

DefaultBufferSize

Default maximum buffer size used to fetch PC/SC responses.

Declaration
uint DefaultBufferSize { get; set; }
Property Value
Type Description
System.UInt32

Methods

| Improve this Doc View Source

CreateIoRequestInstance(Protocol)

Builds an AbstractIoRequest for the current OS.

Declaration
AbstractIoRequest CreateIoRequestInstance(Protocol protocol)
Parameters
Type Name Description
Protocol protocol

T Protocol.

Returns
Type Description
AbstractIoRequest

The concrete AbstractIoRequest object.

| Improve this Doc View Source

CreateReaderStateInstance(String, EventState, EventState)

Build an AbstractReaderState for the current OS.

Declaration
AbstractReaderState CreateReaderStateInstance(string readerName, EventState currentState, EventState eventState)
Parameters
Type Name Description
System.String readerName

Name of the reader.

EventState currentState

Current state.

EventState eventState

Expected state.

Returns
Type Description
AbstractReaderState

The concrete AbstractReaderState object.

| Improve this Doc View Source

SCardCancel(IntPtr)

This function terminates all outstanding actions within a specific resource manager context.

The only requests that you can cancel are those that require waiting for external action by the smart card or user. Any such outstanding action requests will terminate with a status indication that the action was canceled. This is especially useful to force outstanding SCardGetStatusChange(IntPtr, UInt32, AbstractReaderState[], UInt32) calls to terminate.

Declaration
ErrorCode SCardCancel(IntPtr context)
Parameters
Type Name Description
System.IntPtr context

A handle that identifies the resource manager context.

Returns
Type Description
ErrorCode

Success if succeeded.

| Improve this Doc View Source

SCardConnect(IntPtr, String, ShareMode, Protocol, ref IntPtr, ref Protocol)

Establishes a connection (using a specific resource manager context) between the calling application and a smart card contained by a specific reader. If no card exists in the specified reader, an error is returned.

Declaration
ErrorCode SCardConnect(IntPtr context, string readerName, ShareMode shareMode, Protocol preferedProtocol, ref IntPtr card, ref Protocol activeProtocol)
Parameters
Type Name Description
System.IntPtr context

A handle that identifies the resource manager context.

System.String readerName

The name of the reader that contains the target card.

ShareMode shareMode

A flag that indicates whether other applications may form connections to the card.

Protocol preferedProtocol

A bitmask of acceptable protocols for the connection. Possible values may be combined with the OR operation.

System.IntPtr card

A handle that identifies the connection to the smart card in the designated reader.

Protocol activeProtocol

A flag that indicates the established active protocol.

Returns
Type Description
ErrorCode

Success if succeeded.

Remarks

PC/SC: class SCARDCOMM

RESPONSECODE Connect(
	IN STR ReaderName // Friendly name for a Reader
	IN DWORD Flags // Desired access mode information
	IN DWORD PreferredProtocols // Card communications protocols that may be used
	OUT DWORD ActiveProtocol // Protocol actually in use
)
| Improve this Doc View Source

SCardControl(IntPtr, UInt32, Byte[], UInt32, ref Byte[], UInt32, ref UInt32)

Sends a commandAPDU directly to the IFD Handler to be processed by the reader. This is useful for creating client side reader drivers for functions like PIN pads, biometrics, or other extensions to the normal smart card reader that are not normally handled by PC/SC.

Declaration
ErrorCode SCardControl(IntPtr card, uint controlCode, byte[] sendBuffer, uint sendSize, ref byte[] recvBuffer, uint recvSize, ref uint returnedSize)
Parameters
Type Name Description
System.IntPtr card

Reference value returned from SCardConnect

System.UInt32 controlCode

Specifies the control code for the operation. This value identifies the specific operation to be performed.

System.Byte[] sendBuffer

Buffer that contains the data required to perform the operation. This parameter can be null if the controlCode parameter specifies an operation that does not require input data.

System.UInt32 sendSize

Integer that specifies the size, in bytes, of the buffer pointed to by sendBuffer.

System.Byte[] recvBuffer

Buffer that receives the operation's output data. This parameter can be null if the ControlCode parameter specifies an operation that does not produce output data.

System.UInt32 recvSize

Size, in bytes, of the buffer pointed to by recvBuffer. (SCARD_AUTOALLOCATE not allowed)

System.UInt32 returnedSize

Size, in bytes, of the data stored into the buffer pointed to by recvBuffer.

Returns
Type Description
ErrorCode

Success if succeeded.

Remarks

PC/SC: class SCARDCOMM

RESPONSECODE Control(
	IN DWORD ControlCode // Vendor-defined control code
	IN BYTE[] InBuffer // Input data buffer
	IN OUT BYTE[] OutBuffer // Output data buffer
	OUT DWORD OutBufferLength // Length of data in output data buffer
)
| Improve this Doc View Source

SCardDisconnect(IntPtr, Disposition)

Terminates a connection to the connection made through SCardConnect(IntPtr, String, ShareMode, Protocol, ref IntPtr, ref Protocol).

Declaration
ErrorCode SCardDisconnect(IntPtr card, Disposition disposition)
Parameters
Type Name Description
System.IntPtr card

Connection made from SCardConnect

Disposition disposition

Reader function to execute

Returns
Type Description
ErrorCode

Success if succeeded.

Remarks

PC/SC: class SCARDCOMM

RESPONSECODE Disconnect(
	IN DWORD Disposition // Desired Card disposition action
)
| Improve this Doc View Source

SCardEstablishContext(UInt32, Object, Object, ref IntPtr)

Establishes the resource manager context (the scope) within which database operations are performed.

Declaration
ErrorCode SCardEstablishContext(uint scope, object notUsed1, object notUsed2, ref IntPtr context)
Parameters
Type Name Description
System.UInt32 scope

Scope of the resource manager context.

System.Object notUsed1

Reserved for future use and must be null.

System.Object notUsed2

Reserved for future use and must be null.

System.IntPtr context

Handle to the established resource manager context. This handle can now be supplied to other functions attempting to do work within this context.

Returns
Type Description
ErrorCode

Success if succeeded.

Remarks

PC/SC: class RESOURCEMANAGER

RESPONSECODE EstablishContext (
	IN DWORD Scope, // A scope indicator (see below)
	IN DWORD Reserved1, // Reserved for future use to allow privileged administrative programs to act on behalf of another user
	IN DWORD Reserved2 // Reserved for future use to allow privileged administrative programs to act on behalf of another terminal
)
| Improve this Doc View Source

SCardGetAttrib(IntPtr, UInt32, ref Byte[], ref UInt32)

Gets the current reader attributes for the given handle. It does not affect the state of the reader, driver, or card.

Declaration
ErrorCode SCardGetAttrib(IntPtr card, uint attributeId, ref byte[] recvAttribute, ref uint recvAttributeSize)
Parameters
Type Name Description
System.IntPtr card

Reference value returned from SCardConnect(IntPtr, String, ShareMode, Protocol, ref IntPtr, ref Protocol).

System.UInt32 attributeId

Identifier for the attribute to get. Note that vendors may not support all attributes.

System.Byte[] recvAttribute

R-APDU from the card. recvAttribute should be null as the allocation will be automatic (otherwise initial instance will be lost).

System.UInt32 recvAttributeSize

On input, can be AutoAllocate, or the size allocated in recvAttribute. On output, receives the number of bytes in recvAttribute.

Returns
Type Description
ErrorCode

Success if succeeded.

| Improve this Doc View Source

SCardGetStatusChange(IntPtr, UInt32, AbstractReaderState[], UInt32)

The SCardGetStatusChange function blocks execution until the current availability of the cards in a specific set of readers changes. The caller supplies a list of readers to be monitored by an SCARD_READERSTATE_x32OS array and the maximum amount of time (in milliseconds) that it is willing to wait for an action to occur on one of the listed readers. Note that SCardGetStatusChange uses the user-supplied value in the currentState members of the rgReaderStates SCARD_READERSTATE_x32OS array as the definition of the current state of the readers. The function returns when there is a change in availability, having filled in the eventState members of rgReaderStates appropriately.

Declaration
ErrorCode SCardGetStatusChange(IntPtr context, uint timeout, AbstractReaderState[] readerStates, uint readers)
Parameters
Type Name Description
System.IntPtr context

Handle that identifies the resource manager context.

System.UInt32 timeout

Maximum amount of time (in milliseconds) to wait for an action. A value of zero causes the function to return immediately. A value of INFINITE causes this function never to time out.

AbstractReaderState[] readerStates

Array of SCARD_READERSTATE_x32OS structures that specify the readers to watch, and receives the result.

System.UInt32 readers

Number of elements in the readerStates array.

Returns
Type Description
ErrorCode

Success if succeeded.

Remarks

PC/SC: class SCARDTRACK

RESPONSECODE GetStatusChange(
	IN OUT SCARD_READERSTATE_x32OS[] ReaderStates // Array of READERSTATE // structures for readers of interest
	IN DWORD Timeout // Time-out value in milliseconds
)
| Improve this Doc View Source

SCardIsValidContext(IntPtr)

Determines whether a smart card context handle is valid.

Declaration
ErrorCode SCardIsValidContext(IntPtr context)
Parameters
Type Name Description
System.IntPtr context

Handle that identifies the resource manager context.

Returns
Type Description
ErrorCode

Success if the context is valid.

| Improve this Doc View Source

SCardListReaderGroups(IntPtr, ref IntPtr, ref UInt32)

Returns a list of currently available reader groups on the system. If the application sends groups as null then it will return the size of the buffer needed to allocate in size. The group names is a multi-string and separated by a nul character ('\0') and ended by a double nul character.

Declaration
ErrorCode SCardListReaderGroups(IntPtr context, ref IntPtr groups, ref uint size)
Parameters
Type Name Description
System.IntPtr context

Connection context to the PC/SC Resource Manager

System.IntPtr groups

Multi-string buffer (NULL separated) containing list of groups of readers

System.UInt32 size

On input, can be AutoAllocate to autoallocate groups, or the size allocated in groups. On output, receives the number of bytes in groups including NULL's

Returns
Type Description
ErrorCode

Success if succeeded.

Remarks

PC/SC: class RESOURCEQUERY

RESPONSECODE ListReaderGroups(
	OUT STR[] Groups // Array of strings containing the Group names
)
| Improve this Doc View Source

SCardListReaders(IntPtr, String, ref IntPtr, ref UInt32)

Returns a list of currently available readers on the system. If the application sends groups and readers as null then it will return the size of the buffer needed to allocate in size. The reader names is a multi-string and separated by a nul character ('\0') and ended by a double nul character.

Declaration
ErrorCode SCardListReaders(IntPtr context, string groups, ref IntPtr readers, ref uint size)
Parameters
Type Name Description
System.IntPtr context

Connection context to the PC/SC Resource Manager

System.String groups

List of groups to list readers

System.IntPtr readers

Multi-string buffer (NULL separated) containing list of readers

System.UInt32 size

On input, can be AutoAllocate to autoallocate readers, or the size allocated in readers. On output, receives the number of bytes in groups including NULL's

Returns
Type Description
ErrorCode

Success if succeeded.

Remarks

PC/SC: class RESOURCEQUERY

RESPONSECODE ListReaders(
	IN STR[] Groups // Array of strings containing Group names of interest
	OUT STR[] Readers // Array of strings containing Readers within the Groups
)
| Improve this Doc View Source

SCardReconnect(IntPtr, ShareMode, Protocol, Disposition, ref Protocol)

Reestablishes a connection to a reader that was previously connected to using SCardConnect(). In a multi application environment it is possible for an application to reset the card in shared mode. When this occurs any other application trying to access certain commands will be returned the value ResetCard. When this occurs SCardReconnect() must be called in order to acknowledge that the card was reset and allow it to change it's state accordingly.

Declaration
ErrorCode SCardReconnect(IntPtr card, ShareMode shareMode, Protocol preferedProtocol, Disposition initialisation, ref Protocol activeProtocol)
Parameters
Type Name Description
System.IntPtr card

Handle to a previous call to connect

ShareMode shareMode

Mode of connection type: exclusive or shared

Protocol preferedProtocol

Desired protocol use

Disposition initialisation

Desired action taken on the card/reader

Protocol activeProtocol

Established protocol to this connection

Returns
Type Description
ErrorCode

Success if succeeded.

Remarks

PC/SC: class SCARDCOMM

RESPONSECODE Reconnect(
	IN DWORD Flags // desired access mode
	IN DWORD PreferredProtocols // card communications protocols which may be used
	IN DWORD Initialization // Specify card initialization to be performed
	OUT DWORD ActiveProtocol // protocol actually in use
)
| Improve this Doc View Source

SCardReleaseContext(IntPtr)

destroys a communication context to the PC/SC Resource Manager. This must be the last function called in a PC/SC application.

Declaration
ErrorCode SCardReleaseContext(IntPtr context)
Parameters
Type Name Description
System.IntPtr context

Reference value returned from SCardEstablishContext(UInt32, Object, Object, ref IntPtr)

Returns
Type Description
ErrorCode

Success if succeeded.

Remarks

PC/SC: class RESOURCEMANAGER

RESPONSECODE ReleaseContext()
| Improve this Doc View Source

SCardSetAttrib(IntPtr, UInt32, Byte[], UInt32)

Sets the given reader attribute for the given handle. It does not affect the state of the reader, reader driver, or smart card. Not all attributes are supported by all readers (nor can they be set at all times) as many of the attributes are under direct control of the transport protocol.

Declaration
ErrorCode SCardSetAttrib(IntPtr card, uint attributeId, byte[] newAttribute, uint newAttributeSize)
Parameters
Type Name Description
System.IntPtr card

Reference value returned from SCardConnect(IntPtr, String, ShareMode, Protocol, ref IntPtr, ref Protocol).

System.UInt32 attributeId

Specifies the identifier for the attribute to set.

System.Byte[] newAttribute

Pointer to a buffer that supplies the attribute whose identifier is supplied in dwAttrId.

System.UInt32 newAttributeSize

Count of bytes that represent the length of the attribute value in the pbAttr buffer.

Returns
Type Description
ErrorCode

Success if succeeded.

| Improve this Doc View Source

SCardStatus(IntPtr, ref IntPtr, ref UInt32, ref State, ref Protocol, ref IntPtr, ref UInt32)

Provides the current status of a smart card in a reader. You can call it any time after a successful call to SCardConnect(IntPtr, String, ShareMode, Protocol, ref IntPtr, ref Protocol) and before a successful call to SCardDisconnect(IntPtr, Disposition). It does not affect the state of the reader or reader driver.

Use only WITH atrSize=AutoAllocate

Declaration
ErrorCode SCardStatus(IntPtr card, ref IntPtr readerName, ref uint readerNameSize, ref State status, ref Protocol protocol, ref IntPtr atr, ref uint atrSize)
Parameters
Type Name Description
System.IntPtr card

Reference value returned from SCardConnect.

System.IntPtr readerName

List of friendly names (multiple string) by which the currently connected reader is known.

System.UInt32 readerNameSize

On input, supplies the length of the szReaderName buffer.

State status

One of State enumeration

Protocol protocol

Current protocol, if any. The returned value is meaningful only if the returned value of pdwState is SCARD_SPECIFICMODE.

System.IntPtr atr

ATR originally returned by the card

System.UInt32 atrSize

On input, MUST be AutoAllocate, or this method will fail. On output, receives the number of bytes in the ATR string (32 bytes maximum).

Returns
Type Description
ErrorCode

Success if succeeded.

Remarks

PC/SC: class SCARDCOMM

RESPONSECODE Status(
	OUT STR[] Reader // Friendly name of the connected reader
	OUT DWORD State // Current status the connection
	OUT DWORD ActiveProtocol // protocol actually in use
	OUT BYTE Atr[] // ATR data buffer
)
| Improve this Doc View Source

SCardStatus(IntPtr, ref String, ref State, ref Protocol, ref Byte[])

Provides the current status of a smart card in a reader. You can call it any time after a successful call to SCardConnect(IntPtr, String, ShareMode, Protocol, ref IntPtr, ref Protocol) and before a successful call to SCardDisconnect(IntPtr, Disposition). It does not affect the state of the reader or reader driver.

Declaration
ErrorCode SCardStatus(IntPtr card, ref string readerName, ref State state, ref Protocol protocol, ref byte[] atr)
Parameters
Type Name Description
System.IntPtr card

Reference value returned from SCardConnect.

System.String readerName

List of friendly names (multiple string) by which the currently connected reader is known.

State state

One of State enumeration

Protocol protocol

Current protocol, if any. The returned value is meaningful only if the returned value of pdwState is SCARD_SPECIFICMODE.

System.Byte[] atr

ATR originally returned by the card

Returns
Type Description
ErrorCode

Success if succeeded.

Remarks

PC/SC: class SCARDCOMM

RESPONSECODE Status(
	OUT STR[] Reader // Friendly name of the connected reader
	OUT DWORD State // Current status the connection
	OUT DWORD ActiveProtocol // protocol actually in use
	OUT BYTE Atr[] // ATR data buffer
)
| Improve this Doc View Source

SCardStatus(IntPtr, ref State, ref Protocol)

Provides the current status of a smart card in a reader. You can call it any time after a successful call to SCardConnect(IntPtr, String, ShareMode, Protocol, ref IntPtr, ref Protocol) and before a successful call to SCardDisconnect(IntPtr, Disposition). It does not affect the state of the reader or reader driver.

Declaration
ErrorCode SCardStatus(IntPtr card, ref State status, ref Protocol protocol)
Parameters
Type Name Description
System.IntPtr card

Reference value returned from SCardConnect.

State status

One of State enumeration

Protocol protocol

Current protocol, if any. The returned value is meaningful only if the returned value of pdwState is SCARD_SPECIFICMODE.

Returns
Type Description
ErrorCode

Success if succeeded.

Remarks

PC/SC: class SCARDCOMM

RESPONSECODE Status(
	OUT STR[] Reader // Friendly name of the connected reader
	OUT DWORD State // Current status the connection
	OUT DWORD ActiveProtocol // protocol actually in use
	OUT BYTE Atr[] // ATR data buffer
)
| Improve this Doc View Source

SCardTransmit(IntPtr, ref AbstractIoRequest, Byte[], UInt32, ref AbstractIoRequest, ref Byte[], ref UInt32)

Sends a C-APDU to the smart card contained in the reader connected to by SCardConnect(IntPtr, String, ShareMode, Protocol, ref IntPtr, ref Protocol). The card responds and stores this R-APDU in recvBuffer and it's length in recvSize.

Use only WITH recvSize=AutoAllocate

WARNING: SCARD_AUTOALLOCATE is NOT supported on Windows XP and below (winscard.dll limitation)

Declaration
ErrorCode SCardTransmit(IntPtr card, ref AbstractIoRequest sendPci, byte[] sendBuffer, uint sendSize, ref AbstractIoRequest recvPci, ref byte[] recvBuffer, ref uint recvSize)
Parameters
Type Name Description
System.IntPtr card

Connection made from SCardConnect

AbstractIoRequest sendPci

Structure of protocol information

System.Byte[] sendBuffer

C-APDU to send to the card

System.UInt32 sendSize

Length of the C-APDU

AbstractIoRequest recvPci

Structure of protocol information

System.Byte[] recvBuffer

R-APDU from the card. recvBuffer should be null as the allocation will be automatic (otherwise initial instance will be lost).

System.UInt32 recvSize

On input,

MUST be AutoAllocate, or this method will fail. On output, receives the number of bytes in recvBuffer.

Returns
Type Description
ErrorCode

Success if succeeded.

Remarks

PC/SC: class SCARDCOMM

RESPONSECODE Transmit(
	IN SCARD_IO_HEADER SendPci // Send protocol structure
	IN BYTE[] SendBuffer // Data buffer for send data
	IN OUT SCARD_IO_HEADER RecvPci // Receive protocol structure
	IN OUT BYTE[] RecvBuffer // Data buffer for receive data
	OUT DWORD RecvLength // Length of received data
)

Extension Methods

JsonHelpers.WriteToJsonFile(Object, String)
JsonHelpers.WriteToJsonFile(Object, String, Boolean)
JsonHelpers.WriteToJsonString(Object)
JsonHelpers.WriteToJsonString(Object, Boolean)
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX