java.lang.Object
de.gematik.smartcards.pcsc.lib.WinscardLibraryImpl
Class providing a wrapper for native library.
The main purpose for this class is to provide logging at level TRACE for methods in
WinscardLibrary.
- Author:
- gematik
-
Method Summary
Modifier and TypeMethodDescriptionmultiString(byte[] multiString) Converts octet string into a list of strings.static WinscardLibraryImplopenLib()Pseudo constructor.intscardConnect(ScardContext context, String szReader, int dwShareMode, int dwPreferredProtocols, ScardHandleByReference phCard, DwordByReference pdwActiveProtocol) intscardDisconnect(ScardHandle card, int dwPosition) Method wrappingWinscardLibrary.SCardDisconnect(ScardHandle, Dword).intscardEstablishContext(Dword dwScope, com.sun.jna.Pointer pvReserved1, com.sun.jna.Pointer pvReserved2, ScardContextByReference phContext) intscardGetStatusChange(ScardContext context, long dwTimeout, ScardReaderState... rgReaderStates) intscardListReaders(ScardContext context, String mszGroups, byte[] mszReaders, DwordByReference pcchReaders) intscardReleaseContext(ScardContext context) Method wrappingWinscardLibrary.SCardReleaseContext(ScardContext).intscardStatus(ScardHandle card, ByteBuffer mszReaderName, DwordByReference pcchReaderLen, DwordByReference pdwState, DwordByReference pdwProtocol, ByteBuffer pbAtr, DwordByReference pcbAtrLen) byte[]scardTransmit(ScardHandle card, byte[] sendBuffer, double... executionTime)
-
Method Details
-
openLib
Pseudo constructor.Performs the following tasks:
- loads the native platform specific PC/SC library
- copies global PCI (protocol control information) structures for T=0, T=1 and raw out of
native library into the corresponding
ScardIoRequest. - constructs with this information the return value.
- Returns:
WinscardLibraryImpl
-
multiString
Converts octet string into a list of strings.Assumes
UTF-8encoding. The octet string SHALL be encoded as follows:- Each string SHALL be
zero-terminated, i.e. by an octet of value0 = 0x00 = '00'. - An empty string SHALLterminates the list, i.e. two consecutive octets each with a
value of
0 = 0x00 = '00'.
- Parameters:
multiString- octet string containing a list of '0' terminated strings- Returns:
- fixed size list of strings (see
Arrays.asList(Object[])) - Throws:
IllegalArgumentException- if multi-string is not terminated with a null-terminated empty string
- Each string SHALL be
-
scardEstablishContext
public int scardEstablishContext(Dword dwScope, @Nullable com.sun.jna.Pointer pvReserved1, @Nullable com.sun.jna.Pointer pvReserved2, ScardContextByReference phContext) Method wrappingWinscardLibrary.SCardListReaders(ScardContext, ByteBuffer, ByteBuffer, DwordByReference).Observations:
- If no resource manager is running then
SCARD_E_NO_SERVICEis to be expected. - If a resource manager is running then
SCARD_S_SUCCESSis to be expected. - Linux is able to use all scope-values defined in
pcsc-lite.h.in, i.e. from set: [SCARD_SCOPE_USER,SCARD_SCOPE_TERMINAL,SCARD_SCOPE_SYSTEM]. - Windows is unable to use scope
SCARD_SCOPE_TERMINAL.
Implementation recommendations:
- Make sure (or assume) that resource manager is running.
- Use
SCARD_SCOPE_SYSTEMin case TODO - Use
SCARD_SCOPE_USERin case TODO
- Parameters:
dwScope- seeWinscardLibrary.SCardEstablishContext}pvReserved1- seeWinscardLibrary.SCardEstablishContext}pvReserved2- seeWinscardLibrary.SCardEstablishContext}phContext- seeWinscardLibrary.SCardEstablishContext}- Returns:
- see
WinscardLibrary.SCardEstablishContext}
- If no resource manager is running then
-
scardListReaders
public int scardListReaders(@Nullable ScardContext context, @Nullable String mszGroups, @Nullable byte[] mszReaders, DwordByReference pcchReaders) Method wrappingWinscardLibrary.SCardListReaders(ScardContext, ByteBuffer, ByteBuffer, DwordByReference).Observations:
- It does not matter how a
ScardContextis established. - Linux does not support
hContext = null. - Windows:
hContext = nullreturns a list of all readers ever attached to the computer (obviously since OS-installation). - The observed behavior doesn't depend on the value of
mszGroups. Thus,mszGroupscould be any ofNULL,SCARD_ALL_READERS,SCARD_DEFAULT_READERSor a concatenation ofSCARD_ALL_READERSandSCARD_DEFAULT_READERS. - The array backing
mszReaderscan be larger than necessary. - If the size indicated by
pcchReadersis smaller than the size of the to be returnedmszReadersthenSCARD_E_INSUFFICIENT_BUFFERis returned. - Neither Windows nor Linux support
SCARD_AUTOALLOCATE.
Implementation recommendations: In order to get a list of readers actually connected:
- For
hContextuse a real context established with either withSCARD_SCOPE_SYSTEMor withSCARD_SCOPE_USER(presently no differences are known between these two values). - Set
mszGroupstoNULL. - Call the method in a
do .. while()-loop. Within that loop first call this method withmszReadersset toNULLandpcchReaderscontaining 0 in order to retrieve the required buffer size. Then allocate an appropriate buffer formszReadersand call the method again. Loop as long as the second call returnsSCARD_E_INSUFFICIENT_BUFFER. This return value occurs in case another reader is connected between the first and second call and because of the name of that reader a larger buffer is needed.
- Parameters:
context- seeWinscardLibrary.SCardListReaders}mszGroups- seeWinscardLibrary.SCardListReaders}mszReaders- seeWinscardLibrary.SCardListReaders}pcchReaders- seeWinscardLibrary.SCardListReaders}- Returns:
- see
WinscardLibrary.SCardListReaders}
- It does not matter how a
-
scardGetStatusChange
public int scardGetStatusChange(ScardContext context, long dwTimeout, ScardReaderState... rgReaderStates) Method wrappingWinscardLibrary.SCardGetStatusChange(ScardContext, Dword, ScardReaderState[], Dword).Note: Compared to
WinscardLibrary.SCardGetStatusChange(ScardContext, Dword, ScardReaderState[], Dword)this method has no parametercReaders, because this method calculates that value from parameterrgReaderStates.- Parameters:
context- seeWinscardLibrary.SCardGetStatusChange(de.gematik.smartcards.pcsc.lib.ScardContext, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.ScardReaderState[], de.gematik.smartcards.pcsc.lib.Dword)}dwTimeout- seeWinscardLibrary.SCardGetStatusChange(de.gematik.smartcards.pcsc.lib.ScardContext, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.ScardReaderState[], de.gematik.smartcards.pcsc.lib.Dword)}rgReaderStates- seeWinscardLibrary.SCardGetStatusChange(de.gematik.smartcards.pcsc.lib.ScardContext, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.ScardReaderState[], de.gematik.smartcards.pcsc.lib.Dword)}- Returns:
- see
WinscardLibrary.SCardGetStatusChange(de.gematik.smartcards.pcsc.lib.ScardContext, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.ScardReaderState[], de.gematik.smartcards.pcsc.lib.Dword)} - Throws:
IllegalArgumentException- ifreaderStateshas zero lengthNullPointerException- ifrgReaderStatesis null
-
scardConnect
public int scardConnect(ScardContext context, String szReader, int dwShareMode, int dwPreferredProtocols, ScardHandleByReference phCard, DwordByReference pdwActiveProtocol) - Parameters:
context- seeWinscardLibrary.SCardConnect(de.gematik.smartcards.pcsc.lib.ScardContext, java.lang.String, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.ScardHandleByReference, de.gematik.smartcards.pcsc.lib.DwordByReference)}szReader- seeWinscardLibrary.SCardConnect(de.gematik.smartcards.pcsc.lib.ScardContext, java.lang.String, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.ScardHandleByReference, de.gematik.smartcards.pcsc.lib.DwordByReference)}dwShareMode- seeWinscardLibrary.SCardConnect(de.gematik.smartcards.pcsc.lib.ScardContext, java.lang.String, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.ScardHandleByReference, de.gematik.smartcards.pcsc.lib.DwordByReference)}dwPreferredProtocols- seeWinscardLibrary.SCardConnect(de.gematik.smartcards.pcsc.lib.ScardContext, java.lang.String, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.ScardHandleByReference, de.gematik.smartcards.pcsc.lib.DwordByReference)}phCard- seeWinscardLibrary.SCardConnect(de.gematik.smartcards.pcsc.lib.ScardContext, java.lang.String, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.ScardHandleByReference, de.gematik.smartcards.pcsc.lib.DwordByReference)}pdwActiveProtocol- seeWinscardLibrary.SCardConnect(de.gematik.smartcards.pcsc.lib.ScardContext, java.lang.String, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.ScardHandleByReference, de.gematik.smartcards.pcsc.lib.DwordByReference)}- Returns:
- see
WinscardLibrary.SCardConnect(de.gematik.smartcards.pcsc.lib.ScardContext, java.lang.String, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.ScardHandleByReference, de.gematik.smartcards.pcsc.lib.DwordByReference)}
-
scardStatus
public int scardStatus(ScardHandle card, @Nullable ByteBuffer mszReaderName, DwordByReference pcchReaderLen, DwordByReference pdwState, DwordByReference pdwProtocol, ByteBuffer pbAtr, DwordByReference pcbAtrLen) - Parameters:
card- seeWinscardLibrary.SCardStatus(de.gematik.smartcards.pcsc.lib.ScardHandle, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference, de.gematik.smartcards.pcsc.lib.DwordByReference, de.gematik.smartcards.pcsc.lib.DwordByReference, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference)mszReaderName- seeWinscardLibrary.SCardStatus(de.gematik.smartcards.pcsc.lib.ScardHandle, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference, de.gematik.smartcards.pcsc.lib.DwordByReference, de.gematik.smartcards.pcsc.lib.DwordByReference, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference)pcchReaderLen- seeWinscardLibrary.SCardStatus(de.gematik.smartcards.pcsc.lib.ScardHandle, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference, de.gematik.smartcards.pcsc.lib.DwordByReference, de.gematik.smartcards.pcsc.lib.DwordByReference, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference)pdwState- seeWinscardLibrary.SCardStatus(de.gematik.smartcards.pcsc.lib.ScardHandle, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference, de.gematik.smartcards.pcsc.lib.DwordByReference, de.gematik.smartcards.pcsc.lib.DwordByReference, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference)pdwProtocol- seeWinscardLibrary.SCardStatus(de.gematik.smartcards.pcsc.lib.ScardHandle, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference, de.gematik.smartcards.pcsc.lib.DwordByReference, de.gematik.smartcards.pcsc.lib.DwordByReference, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference)pbAtr- seeWinscardLibrary.SCardStatus(de.gematik.smartcards.pcsc.lib.ScardHandle, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference, de.gematik.smartcards.pcsc.lib.DwordByReference, de.gematik.smartcards.pcsc.lib.DwordByReference, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference)pcbAtrLen- seeWinscardLibrary.SCardStatus(de.gematik.smartcards.pcsc.lib.ScardHandle, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference, de.gematik.smartcards.pcsc.lib.DwordByReference, de.gematik.smartcards.pcsc.lib.DwordByReference, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference)- Returns:
- see
WinscardLibrary.SCardStatus(de.gematik.smartcards.pcsc.lib.ScardHandle, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference, de.gematik.smartcards.pcsc.lib.DwordByReference, de.gematik.smartcards.pcsc.lib.DwordByReference, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference)
-
scardTransmit
public byte[] scardTransmit(ScardHandle card, byte[] sendBuffer, double... executionTime) throws PcscException - Parameters:
card- seeWinscardLibrary.SCardTransmit(de.gematik.smartcards.pcsc.lib.ScardHandle, de.gematik.smartcards.pcsc.lib.ScardIoRequest, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.Dword, de.gematik.smartcards.pcsc.lib.ScardIoRequest, java.nio.ByteBuffer, de.gematik.smartcards.pcsc.lib.DwordByReference)}sendBuffer- command message to be transmittedexecutionTime- [OUT] parameter with at least one element which receives the execution time of the underlying library call in seconds- Returns:
- corresponding response message
- Throws:
PcscException- if the card operation fails
-
scardDisconnect
Method wrappingWinscardLibrary.SCardDisconnect(ScardHandle, Dword).- Parameters:
card- seeWinscardLibrary.SCardDisconnect(de.gematik.smartcards.pcsc.lib.ScardHandle, de.gematik.smartcards.pcsc.lib.Dword)}dwPosition- seeWinscardLibrary.SCardDisconnect(de.gematik.smartcards.pcsc.lib.ScardHandle, de.gematik.smartcards.pcsc.lib.Dword)}- Returns:
- see
WinscardLibrary.SCardDisconnect(de.gematik.smartcards.pcsc.lib.ScardHandle, de.gematik.smartcards.pcsc.lib.Dword)}
-
scardReleaseContext
Method wrappingWinscardLibrary.SCardReleaseContext(ScardContext).Observations:
- It does not matter if
SCardEstablishContextwas not successful. The context can be released successfully anyway. - A context can be released only once. Another call of
SCardReleaseContextproducesSCARD_E_INVALID_HANDLE.
Implementation recommendations:
- Either assume that the used
ScardContextis valid, or - check validity with TODO #SCardIsValidContext(ScardContext).
- Parameters:
context- seeWinscardLibrary.SCardReleaseContext}- Returns:
- see
WinscardLibrary.SCardReleaseContext}
- It does not matter if
-