com.cryptware.jscapi
Class CommandAPDU

java.lang.Object
  extended by com.cryptware.jscapi.CommandAPDU

public class CommandAPDU
extends java.lang.Object

Implements a Command APDU
A smart card command is encoded in a Command APDU. A T = 1 Command APDU is similar to a record made by seven fields, each one 8-bit length: CLA (Class), INS ( INS (Class Instruction), P1 (Parameter 1), P2 (Parameter 2 ), LC (Length of the Command), DATA (Command DATA), LE (Length of Expected). The first four fields represent a mandatory header specifying a particular command, the three remaining fields identify an optional body containing eventual input parameters. The CLA byte indicates the class to which the command belongs (that is in which section of ISO 7816 standard defines the command or if it is included in a proprietary set of commands) and the submission mode (normal or SM). The INS field individuates a command inside the class specified by CLA. P1 and P2 are both additional parameters specific to a particular command. The LC field holds the length of the following DATA field (though, it could be omitted if there is no DATA field). DATA contains all data being processed via the command (for example, data being written in a file). Finally, LE specifies the response’s expected length sent by the microchip for the command. A T = 0 Command APDU is a bit different from the T = 1 ones. T = 0 splits commands APDUs in APDUs for writing and for reading (differently from T = 1 where an APDU can write data and receive response data at the same time). In other words a T = 0 a command APDU which writes data cannot receive response data other than the status words (see next paragraph). A T = 0 Command APDU has CLA, INS, P1 and P2 but defines P3 as the length of DATA field if it is a writing APDU (i.e. the purpose of the command is to send something to the smart card; it stands for LC) or as the length of the expected response if it is a reading APDU (i.e. the purpose of the command is to read something from the smart card; it stands for LE). Each APDU Command is executed by the smart card operating system and affects the currently selected EF or Dedicated File (at startup Master File is automatically selected).

Author:
Ugo Chirico

Constructor Summary
CommandAPDU()
          Default Constructor
CommandAPDU(byte[] apdu)
           
CommandAPDU(int CLA, int INS, int P1, int P2)
           
CommandAPDU(int CLA, int INS, int P1, int P2, int P3LE)
          Constructor for T=0 APDU
CommandAPDU(int CLA, int INS, int P1, int P2, int LC, byte[] data)
           
CommandAPDU(int CLA, int INS, int P1, int P2, int LC, byte[] data, int LE)
           
 
Method Summary
 byte[] getBytes()
           
 int getCLA()
           
 byte[] getData()
           
 int getINS()
           
 int getLC()
           
 int getLE()
           
 int getP1()
           
 int getP2()
           
 int getP3()
           
 void setCLA(int cla)
           
 void setData(byte[] data)
           
 void setData(byte[] data, int offset, int len)
           
 void setINS(int ins)
           
 void setLC(int lc)
           
 void setLE(int le)
           
 void setP1(int p1)
           
 void setP2(int p2)
           
 void setP3(int p3)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandAPDU

public CommandAPDU()
Default Constructor


CommandAPDU

public CommandAPDU(int CLA,
                   int INS,
                   int P1,
                   int P2)
Parameters:
CLA -
INS -
P1 -
P2 -

CommandAPDU

public CommandAPDU(int CLA,
                   int INS,
                   int P1,
                   int P2,
                   int P3LE)
Constructor for T=0 APDU

Parameters:
CLA -
INS -
P1 -
P2 -
P3LE -

CommandAPDU

public CommandAPDU(int CLA,
                   int INS,
                   int P1,
                   int P2,
                   int LC,
                   byte[] data)
Parameters:
CLA -
INS -
P1 -
P2 -
LC -
data -

CommandAPDU

public CommandAPDU(int CLA,
                   int INS,
                   int P1,
                   int P2,
                   int LC,
                   byte[] data,
                   int LE)
Parameters:
CLA -
INS -
P1 -
P2 -
LC -
data -
LE -

CommandAPDU

public CommandAPDU(byte[] apdu)
Parameters:
apdu -
Method Detail

getCLA

public int getCLA()
Returns:
CLA

setCLA

public void setCLA(int cla)
Parameters:
cla -

getINS

public int getINS()
Returns:
INS

setINS

public void setINS(int ins)
Parameters:
ins -

getP1

public int getP1()
Returns:
P1

setP1

public void setP1(int p1)
Parameters:
p1 -

getP2

public int getP2()
Returns:
P2

setP2

public void setP2(int p2)
Parameters:
p2 -

getLC

public int getLC()
Returns:
LC

setLC

public void setLC(int lc)
Parameters:
lc -

getP3

public int getP3()
Returns:
P3

setP3

public void setP3(int p3)
Parameters:
p3 -

getData

public byte[] getData()
Returns:
the data field

setData

public void setData(byte[] data)
Parameters:
data -

setData

public void setData(byte[] data,
                    int offset,
                    int len)
Parameters:
data -
offset -
len -

getLE

public int getLE()
Returns:
LE

setLE

public void setLE(int le)
Parameters:
le -

getBytes

public byte[] getBytes()
Returns:
the APDU buffer