com.linuxnet.jpcsc
Class Card

java.lang.Object
  extended bycom.linuxnet.jpcsc.Card

public final class Card
extends java.lang.Object

The Card class offers PCSC functions related to connecting, disconnecting and transferring data to cards.


Method Summary
 void BeginTransaction()
          Signal the start of a transaction.
 byte[] Control(int dwControlCode, byte[] in)
          Wrapper for SCardControl().
 byte[] Control(int dwControlCode, byte[] in, int off, int len)
          Wrapper for SCardControl().
 void Disconnect()
          Default disconnect from card (LEAVE_CARD).
 void Disconnect(int param)
          Disconnect from card.
 void EndTransaction(int disposition)
          Signal end of a transaction.
protected  void finalize()
          Finalizer.
 byte[] GetAttrib(int dwAttribId)
          Get an attribute from the IFD Handler.
 int getProto()
          Return protocol used.
 boolean getResendOnWrongLe()
          Return flag indicating the transparent handling of resend on wrong Le
 boolean getT0GetResponse()
          Return flag indicating the transparent handling of T0 GetResponse.
 void Reconnect(int dwSharedMode, int dwPreferredProtos, int dwInitialization)
          Reconnect to card.
 void SetAttrib(int dwAttribId, byte[] attr)
          Set an attribute of the IFD Handler.
 void setResendOnWrongLe(boolean b)
          Switch on/off transparent handling of resend on wrong Le
 void setT0GetResponse(boolean b)
          Switch on/off transparent handling of T0 GetResponse.
 State Status()
          Return status of connection.
 void Status(State state)
          Return status of connection in the specified state object.
 java.lang.String toString()
          Return string representation.
 byte[] Transmit(Apdu apdu)
          Transmit given APDU.
 byte[] Transmit(byte[] in, int off, int len)
          Transmit data.
 int Transmit(byte[] in, int inoff, int len, byte[] out, int outoff)
          Transmit data.
 byte[] Transmit(int cla, int ins, int p1, int p2, byte[] in)
          Transmit data to the card.
 byte[] Transmit(int cla, int ins, int p1, int p2, byte[] in, int le)
          Transmit data to the card.
 byte[] Transmit(int cla, int ins, int p1, int p2, byte[] in, int off, int len)
          Transmit data to the card.
 byte[] Transmit(int cla, int ins, int p1, int p2, byte[] in, int off, int len, int le)
          Transmit data to the card.
 byte[] Transmit(int cla, int ins, int p1, int p2, int p3, byte[] in, int off, int le)
          Transmit data to the card.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

toString

public final java.lang.String toString()
Return string representation.


getProto

public final int getProto()
Return protocol used.


getT0GetResponse

public final boolean getT0GetResponse()
Return flag indicating the transparent handling of T0 GetResponse.


setT0GetResponse

public final void setT0GetResponse(boolean b)
Switch on/off transparent handling of T0 GetResponse.


getResendOnWrongLe

public final boolean getResendOnWrongLe()
Return flag indicating the transparent handling of resend on wrong Le


setResendOnWrongLe

public final void setResendOnWrongLe(boolean b)
Switch on/off transparent handling of resend on wrong Le


finalize

protected final void finalize()
Finalizer. Invokes Disconnect() with parameter LEAVE_CARD.


Disconnect

public final void Disconnect()
Default disconnect from card (LEAVE_CARD).


Disconnect

public final void Disconnect(int param)
Disconnect from card. Valid parameters are LEAVE_CARD, RESET_CARD, UNPOWER_CARD, EJECT_CARD.

Parameters:
param - PCSC.LEAVE_CARD, PCSC.RESET_CARD, PCSC.UNPOWER_CARD, PCSC.EJECT_CARD.

Reconnect

public final void Reconnect(int dwSharedMode,
                            int dwPreferredProtos,
                            int dwInitialization)
Reconnect to card. Valid parameters are SHARE_EXCLUSIVE, SHARE_SHARED, SHARE_DIRECT for the sharing mode, PROTOCOL_T0, PROTOCOL_T1, PROTOCOL_RAW, PROTOCOL_ANY for the protocol, and LEAVE_CARD, EJECT_CARD, RESET_CARD and UNPOWER_CARD for the initialization parameter.

Parameters:
dwSharedMode - PCSC.SHARE_EXCLUSIVE, PCSC.SHARE_SHARED or PCSC.SHARE_DIRECT.
dwPreferredProtos - PCSC.PROTOCOL_T0, PCSC.PROTOCOL_T1, PCSC.PROTOCOL_RAW, PCSC.PROTOCOL_ANY.
dwInitialization - PCSC.LEAVE_CARD, PCSC.EJECT_CARD, PCSC.RESET_CARD and PCSC.UNPOWER_CARD.

Transmit

public final byte[] Transmit(Apdu apdu)
Transmit given APDU. Result is returned in a newly instantiated bytearray. In case of error, the native code raises a PCSCException.

Returns:
response from the card.

Transmit

public final byte[] Transmit(byte[] in,
                             int off,
                             int len)
Transmit data. Result is returned in a newly instantiated bytearray. The specified range of the parameter array must contain a properly constructed APDU. In case of error, the native code raises a PCSCException.

Parameters:
in - buffer holding the APDU.
off - offset into buffer where the APDU starts.
len - length of APDU.
Returns:
response from the card.

Transmit

public final byte[] Transmit(int cla,
                             int ins,
                             int p1,
                             int p2,
                             int p3,
                             byte[] in,
                             int off,
                             int le)
Transmit data to the card. Result is returned in a newly created array. The given APDU header information and data are stored in a newly created temporary array and passed to the native Transmit routines.

Parameters:
cla - CLA byte of APDU (byte #0)
ins - INS byte of APDU (byte #1)
p1 - P1 byte of APDU (byte #2)
p2 - P2 byte of APDU (byte #3)
p3 - P3 or LC byte of APDU (byte #4). This byte is omitted if parameter has value -1, otherwise it contains number of bytes in buffer in sent to card.
in - byte array containing command data of APDU.
off - offset starting at which data sending is to begin
le - LE byte of APDU (appended to APDU). This byte is omitted if parameter has value -1.
Returns:
response APDU as a byte array
Throws:
PCSCException - if communication failed or if some parameters are wrong

Transmit

public final byte[] Transmit(int cla,
                             int ins,
                             int p1,
                             int p2,
                             byte[] in,
                             int off,
                             int len,
                             int le)
Transmit data to the card. Result is returned in a newly created array. The given APDU header information and data are stored in a newly created temporary array and passed to the native Transmit routines. The given range of the given in buffer is sent to the card.

Parameters:
cla - CLA byte of APDU (byte #0)
ins - INS byte of APDU (byte #1)
p1 - P1 byte of APDU (byte #2)
p2 - P2 byte of APDU (byte #3)
in - byte array containing command data of APDU.
off - offset starting at which data sending is to begin
len - number of bytes to be transmitted
le - LE byte of APDU (appended to APDU). This byte is omitted if parameter has value -1.
Returns:
response APDU as a byte array
Throws:
PCSCException - if communication failed or if some parameters are wrong

Transmit

public final byte[] Transmit(int cla,
                             int ins,
                             int p1,
                             int p2,
                             byte[] in,
                             int le)
Transmit data to the card. Result is returned in a newly created array. The given APDU header information and data are stored in a newly created temporary array and passed to the native Transmit routines. The given in buffer is fully sent to the card.

Parameters:
cla - CLA byte of APDU (byte #0)
ins - INS byte of APDU (byte #1)
p1 - P1 byte of APDU (byte #2)
p2 - P2 byte of APDU (byte #3)
in - byte array containing command data of APDU.
le - LE byte of APDU (appended to APDU). This byte is omitted if parameter has value -1.
Returns:
response APDU as a byte array
Throws:
PCSCException - if communication failed or if some parameters are wrong

Transmit

public final byte[] Transmit(int cla,
                             int ins,
                             int p1,
                             int p2,
                             byte[] in,
                             int off,
                             int len)
Transmit data to the card. Result is returned in a newly created array. The given APDU header information and data are stored in a newly created temporary array and passed to the native Transmit routines. The given range of the in buffer is sent and the expected length field is left out.

Parameters:
cla - CLA byte of APDU (byte #0)
ins - INS byte of APDU (byte #1)
p1 - P1 byte of APDU (byte #2)
p2 - P2 byte of APDU (byte #3)
in - byte array containing command data of APDU.
off - offset starting at which data sending is to begin
len - number of bytes to be transmitted
Returns:
response APDU as a byte array
Throws:
PCSCException - if communication failed or if some parameters are wrong

Transmit

public final byte[] Transmit(int cla,
                             int ins,
                             int p1,
                             int p2,
                             byte[] in)
Transmit data to the card. Result is returned in a newly created array. The given APDU header information and data are stored in a newly created temporary array and passed to the native Transmit routines. The in buffer is sent completely, the expected length field is left out.

Parameters:
cla - CLA byte of APDU (byte #0)
ins - INS byte of APDU (byte #1)
p1 - P1 byte of APDU (byte #2)
p2 - P2 byte of APDU (byte #3)
in - byte array containing command data of APDU.
Returns:
response APDU as a byte array
Throws:
PCSCException - if communication failed or if some parameters are wrong

Transmit

public final int Transmit(byte[] in,
                          int inoff,
                          int len,
                          byte[] out,
                          int outoff)
Transmit data. Result is returned in the passed array at given offset. The range within the given buffer in must hold a properly constructed APDU. On success, the returned value will hold the number of bytes stored in the result buffer. In case of an error, a PCSCException is raised. The exception instance then contains the PCSC error code. If sending the APDU was successful, the number of bytes received are returned.

Parameters:
in - buffer holding the APDU.
inoff - offset into buffer where the APDU starts.
len - length of APDU.
out - buffer where to store the card result.
outoff - offset into buffer where to store reponse.
Returns:
number of bytes returned by the card.

Status

public final State Status()
Return status of connection. The State object contains the state of the connection in the dwCurrentState field (which might be PCSC.ABSENT, PCSC.PRESENT, PCSC.SWALLOWED, PCSC.POWERED, PCSC.NEGOTIABLE or PCSC.SPECIFIC). The protocol of the connection is stored in the State.proto field.

Returns:
state of the connection.

Status

public final void Status(State state)
Return status of connection in the specified state object. The State object contains the state of the connection in the dwCurrentState field (which might be PCSC.ABSENT, PCSC.PRESENT, PCSC.SWALLOWED, PCSC.POWERED, PCSC.NEGOTIABLE or PCSC.SPECIFIC). The protocol of the connection is stored in the State.proto field.

Parameters:
state - of the connection.

BeginTransaction

public final void BeginTransaction()
Signal the start of a transaction.


EndTransaction

public final void EndTransaction(int disposition)
Signal end of a transaction. The parameter dispositon may either be LEAVE_CARD, RESET_CARD, UNPOWER_CARD or EJECT_CARD.

Parameters:
disposition - LEAVE_CARD, RESET_CARD, UNPOWER_CARD, EJECT_CARD.

Control

public final byte[] Control(int dwControlCode,
                            byte[] in)
Wrapper for SCardControl(). Note that Muscle PCSC (< 1.2.9) does not support the dwControlCode parameter.


Control

public final byte[] Control(int dwControlCode,
                            byte[] in,
                            int off,
                            int len)
Wrapper for SCardControl(). Note that Muscle PCSC (< 1.2.9) does not support the dwControlCode parameter.


SetAttrib

public final void SetAttrib(int dwAttribId,
                            byte[] attr)
Set an attribute of the IFD Handler.


GetAttrib

public final byte[] GetAttrib(int dwAttribId)
Get an attribute from the IFD Handler.