com.jaccal.pcsc
Class JaccalPCSC

java.lang.Object
  extended bycom.jaccal.pcsc.JaccalPCSC

public class JaccalPCSC
extends Object

Author:
Thomas Tarpin-Lyonnet

JaccalPCSC class provides a set of native methods allowing to power on, power down and send APDU command to a card. JaccalPCSC class is in charge of establish the context with the system and in charge of getting the list of the smart card readers installed in the system.

How to use JaccalPCSC ?

Example:
         try {
         	String[] readerList;
         

// Create a JaccalPCSC object and initialize it // Initialisation means: // - Allocating enough memory for storing all the reader names // attached to the system // - Establishing a context with the system // - Retrieving the list of all the readers attached to the system JaccalPCSC jaccalPcsc = new JaccalPCSC();

// Select MF APDU command byte [] selectMF = {0x00,0xA4,0x00,0x00,0x02,0x3F,0x00};

// Retrieve the list of the readers bind to the system readerList = jaccalPcsc.getReaderList();

// Connect to the first reader in the list // (power on the card inserted in the first reader in the list jaccalPcsc.connectCard(readerList[0],PCSC.SCARD_SHARE_SHARED);

// Send the select APDU command byte [] resp = jaccalPcsc.transmitApdu(selectMF,0,selectMF.length);

// Power Off the card jaccalPcsc.disconnectCard(PCSC.SCARD_UNPOWER_CARD);

} catch (JaccalPCSCException e) { System.out.println(e.getMessage()); }


Field Summary
private  byte[] cardAtr
           
private  long cardHandle
           
private  long cardProtocol
           
private  String cardReader
           
private static long contextHandle
           
private static String[] readerList
           
private  boolean t0GetResponse
           
 
Constructor Summary
JaccalPCSC()
          Allocate enough space to contain 20 smart card readers in the cardReaderList
JaccalPCSC(int nbReader2Allocate)
          Define the number of readers to be allocated in the cardReaderList.
 
Method Summary
private  void adjustReaderList()
           
private  int connect(String readerName, int dwShareMode, long dwProtocol)
           
 void connectCard(int shareMode)
          Power on the card in the reader name that has been set previously.
 void connectCard(String readerName, int shareMode)
          Power on the card inserted in the reader name given in parameters.
 void connectCard(String readerName, int shareMode, long preferedProtocol)
          Power on the card inserted in the reader name given in parameters.
private  int disconnect(int dwDisposition)
           
 void disconnectCard(int swDisposition)
          Power off the card.
private  int establishContext(int dwScope)
           
 byte[] getCardAtr()
          Returns the ATR of the card currently powered on.
 long getCardHandle()
          Returns the handle of the card currently powered on
 String getCardReader()
          Get the name of the JaccalPCSC active reader
 String[] getReaderList()
          Returns the list of the smart card readers attached to the system.
private  int getReadersList()
           
 void getStatus()
          Get the status of the card (inserted, removed etc ...)
private  int getStatusChange()
           
private  void initialize()
          Initialize the context and get the list of the smart card readers bind to the system
 boolean isT0GetResponse()
          Indicates if Get Response apdu command is automatically chained whenever
the card status words are 61xxh with xxh the number of bytes available in the card
IO buffer.
 void setCardReader(String cardReader)
          Set the name of the JaccalPCSC active reader
private static void setReaderList(String[] readerList)
           
 void setT0GetResponse(boolean getResponse)
          Set or unset the automatic chaining of Get Reponse APDU command whenever its needed.
private  byte[] transmit(byte[] apduCmd, int offset, int cmdLen, byte[] errorCode)
           
 byte[] transmitApdu(byte[] cmd, int offsetInCmdBuff, int cmdLen)
          Send a APDU command as defined in ISO7816-4 to the card that has been powered on by a previous connectCard call.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

contextHandle

private static long contextHandle

readerList

private static String[] readerList

cardHandle

private long cardHandle

cardReader

private String cardReader

cardAtr

private byte[] cardAtr

cardProtocol

private long cardProtocol

t0GetResponse

private boolean t0GetResponse
Constructor Detail

JaccalPCSC

public JaccalPCSC(int nbReader2Allocate)
           throws JaccalPCSCException
Define the number of readers to be allocated in the cardReaderList. Mostly, this constructor will be used if the default value of 20 allocated smart card readers, in cardReaderList, is not enough.

Parameters:
nbReader2Allocate -

JaccalPCSC

public JaccalPCSC()
           throws JaccalPCSCException
Allocate enough space to contain 20 smart card readers in the cardReaderList

Method Detail

establishContext

private int establishContext(int dwScope)

connect

private int connect(String readerName,
                    int dwShareMode,
                    long dwProtocol)

disconnect

private int disconnect(int dwDisposition)

getReadersList

private int getReadersList()

transmit

private byte[] transmit(byte[] apduCmd,
                        int offset,
                        int cmdLen,
                        byte[] errorCode)

getStatusChange

private int getStatusChange()

initialize

private void initialize()
                 throws JaccalPCSCException
Initialize the context and get the list of the smart card readers bind to the system

Throws:
JaccalPCSCException

connectCard

public void connectCard(String readerName,
                        int shareMode)
                 throws JaccalPCSCException
Power on the card inserted in the reader name given in parameters. shareMode can take the following values: SCARD_SHARE_EXCLUSIVE, SCARD_SHARE_SHARED or SCARD_SHARE_DIRECT

Parameters:
readerName -
shareMode -
Throws:
JaccalPCSCException

connectCard

public void connectCard(String readerName,
                        int shareMode,
                        long preferedProtocol)
                 throws JaccalPCSCException
Power on the card inserted in the reader name given in parameters.

Parameters:
readerName -
shareMode -
preferedProtocol -
Throws:
JaccalPCSCException

connectCard

public void connectCard(int shareMode)
                 throws JaccalPCSCException
Power on the card in the reader name that has been set previously. shareMode can take the following values: SCARD_SHARE_EXCLUSIVE, SCARD_SHARE_SHARED or SCARD_SHARE_DIRECT

Parameters:
shareMode -
Throws:
JaccalPCSCException

disconnectCard

public void disconnectCard(int swDisposition)
                    throws JaccalPCSCException
Power off the card.

Parameters:
swDisposition - tells what kind of power off to perform. Can be SCARD_LEAVE_CARD, SCARD_RESET_CARD, SCARD_UNPOWER_CARD or SCARD_EJECT_CARD
Throws:
JaccalPCSCException

getStatus

public void getStatus()
               throws JaccalPCSCException
Get the status of the card (inserted, removed etc ...)

Throws:
JaccalPCSCException

transmitApdu

public byte[] transmitApdu(byte[] cmd,
                           int offsetInCmdBuff,
                           int cmdLen)
                    throws JaccalPCSCException
Send a APDU command as defined in ISO7816-4 to the card that has been powered on by a previous connectCard call.

Parameters:
cmd -
offsetInCmdBuff -
cmdLen -
Returns:
The card response composed of the response data + the card status words (SW1 & SW2)
Throws:
JaccalPCSCException

getReaderList

public String[] getReaderList()
Returns the list of the smart card readers attached to the system.

Returns:
Returns the readerList.

getCardHandle

public long getCardHandle()
Returns the handle of the card currently powered on

Returns:
Returns the cardHandle.

getCardAtr

public byte[] getCardAtr()
Returns the ATR of the card currently powered on.

Returns:
Returns the cardAtr.

setReaderList

private static void setReaderList(String[] readerList)
Parameters:
readerList - The readerList to set.

adjustReaderList

private void adjustReaderList()

setCardReader

public void setCardReader(String cardReader)
Set the name of the JaccalPCSC active reader

Parameters:
cardReader -

getCardReader

public String getCardReader()
Get the name of the JaccalPCSC active reader

Returns:
The active reader name

isT0GetResponse

public boolean isT0GetResponse()
Indicates if Get Response apdu command is automatically chained whenever
the card status words are 61xxh with xxh the number of bytes available in the card
IO buffer.

Returns:
Returns the t0GetResponse.

setT0GetResponse

public void setT0GetResponse(boolean getResponse)
Set or unset the automatic chaining of Get Reponse APDU command whenever its needed.

Parameters:
getResponse - The t0GetResponse to set.


Copyright © 2005 Chang Sau Sheong, Thomas Tarpin-Lyonnet. All Rights Reserved.