com.ibm.jc
Class JCard

java.lang.Object
  extended bycom.ibm.jc.JCard

public class JCard
extends java.lang.Object

This class represents a JavaCard connected to a terminal communicating via a certain logical channel.


Field Summary
static int CHANNEL_CLOSE
          Logical channel management mode.
static int CHANNEL_OPEN
          Logical channel management mode.
 
Constructor Summary
JCard(JCTerminal terminal, ATR atr, int timeout)
          Create a card representative.
 
Method Summary
 ATR getATR()
           
 int getChannel()
          Returns the logical channel number currently used.
 JCTerminal getTerminal()
           
 java.lang.String identifyCard(java.io.PrintWriter out)
          Returns the class name of the Card Manager implementation which fits to this JavaCard.
 int manageChannel(int mode)
          Used to open and close Supplementary Logical Channels.
 void reset()
          Reset card and get a new ATR.
 byte[] send(int nad, byte[] toSend, int offset, int len)
          Send data to the card via the current logical channel.
 byte[] send(int nad, int cla, int ins, int p1, int p2, int p3, byte[] toSend, int offset, int le)
          Send data to the card via the current logical channel.
 void setChannel(int ch)
          Sets the logical channel number used in any subsequent APDU communication.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHANNEL_OPEN

public static final int CHANNEL_OPEN
Logical channel management mode. Opens the next available supplementary logical channel.

See Also:
manageChannel(int), Constant Field Values

CHANNEL_CLOSE

public static final int CHANNEL_CLOSE
Logical channel management mode. Closes the current logical channel.

See Also:
manageChannel(int), getChannel(), setChannel(int), Constant Field Values
Constructor Detail

JCard

public JCard(JCTerminal terminal,
             ATR atr,
             int timeout)
Create a card representative.

Parameters:
terminal - the terminal the card is plugged is or will be plugged in. The terminal must be initialized and open.
atr - the ATR as returned from the card or null. If null then this object will request an ATR from the terminal object.
timeout - timeout in ms to wait for card insertion.
See Also:
JCTerminal
Method Detail

reset

public void reset()
Reset card and get a new ATR. The default channel (zero) becomes the current logical channel.


getTerminal

public JCTerminal getTerminal()
Returns:
the terminal object the card is plugged in.

getATR

public ATR getATR()
Returns:
the ATR object from the last reset.

identifyCard

public java.lang.String identifyCard(java.io.PrintWriter out)
Returns the class name of the Card Manager implementation which fits to this JavaCard. This is achieved by inspecting the ATR.

Parameters:
out - if not null manufacturer info is printed.
Returns:
card manager class name.

send

public byte[] send(int nad,
                   byte[] toSend,
                   int offset,
                   int len)
Send data to the card via the current logical channel. To make applications channel independent the CLA byte should indicate logical channel zero. Then the CLA byte is automatically modified to address the current channel.

Parameters:
nad - node address to which data is being sent (high nibble = destination address, low = source address). Address values: 2=host, 1=terminal, 0=card. A value of 0 means from host to card.
toSend - byte array containing APDU to be sent (logical channel (two least significant bits) should be zero).
offset - offset into toSend.
len - number of bytes to be transmitted
Returns:
response APDU as a byte array
Throws:
JCException - if communication failed or if some parameters are wrong
See Also:
setChannel(int), getChannel(), manageChannel(int)

send

public byte[] send(int nad,
                   int cla,
                   int ins,
                   int p1,
                   int p2,
                   int p3,
                   byte[] toSend,
                   int offset,
                   int le)
Send data to the card via the current logical channel. To make applications channel independent the CLA byte should indicate logical channel zero. Then the CLA byte is automatically modified to address the current channel.

Parameters:
nad - node address to which data is being sent. A value of 0 means from host to card.
cla - CLA byte of APDU (byte #0) (logical channel (two least significant bits) should be zero)
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.
toSend - byte array containing command data of APDU. Command data starts at byte #5.
offset - 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:
JCException - if communication failed or if some parameters are wrong
See Also:
setChannel(int), getChannel(), manageChannel(int)

manageChannel

public int manageChannel(int mode)
Used to open and close Supplementary Logical Channels. Uses the ISO 7816-4/Global Platform MANAGE CHANNEL command.

Parameters:
mode - indicates if the next available supplementary logical channel is to be opened (CHANNEL_OPEN) or the current logical channel is to be closed (CHANNEL_CLOSE). Upon opening a channel the newly opened channel becomes the current channel. Upon closing a supplementary channel the default channel (zero) becomes the current channel.
Returns:
the current logical channel (new channel or zero depending on mode).
Throws:
JCException - if the command failed or if parameters are wrong
See Also:
setChannel(int), getChannel(), CHANNEL_OPEN, CHANNEL_CLOSE

setChannel

public void setChannel(int ch)
Sets the logical channel number used in any subsequent APDU communication. The CLA byte of any APDU header sent to the card is automatically modified to reflect the logical channel number as defined in ISO 7816-4. Modification only takes place if the original CLA byte indicates channel zero, otherwise the given channel info is maintained. By default the logical channel number is zero.

Parameters:
ch - the desired logical channel (in the range 0-3).
Throws:
JCException - if the channel number is invalid.
See Also:
getChannel(), manageChannel(int), send(int, byte[], int, int)

getChannel

public int getChannel()
Returns the logical channel number currently used.

See Also:
setChannel(int), manageChannel(int), send(int, byte[], int, int)