com.dalsemi.onewire.container
Class CommandAPDU

java.lang.Object
  |
  +--com.dalsemi.onewire.container.CommandAPDU

public class CommandAPDU
extends java.lang.Object

A CommandAPDU represents an ISO 7816-4 specified Application Protocol Data Unit (APDU) sent to a smart card. A response from the smart card is in turn represented by a ResponseAPDU.

According to ISO 7816-4, a CommandAPDU has the following format:

                  HEADER         |           BODY
         CLA    INS    P1    P2  |  [LC]    [DATA]    [LE]
 
where

Version:
0.00, 28 Aug 2000

Field Summary
static int CLA
          Constant for addressing CLA in the CommandAPDU buffer.
static int INS
          Constant for addressing INS in the CommandAPDU buffer.
static int LC
          Constant for addressing LC in the CommandAPDU buffer.
static int P1
          Constant for addressing P1 in the CommandAPDU buffer.
static int P2
          Constant for addressing P2 in the CommandAPDU buffer.
 
Constructor Summary
CommandAPDU(byte[] buffer)
          Constructs a new ISO 7816-4 CommandAPDU.
CommandAPDU(byte cla, byte ins, byte p1, byte p2)
          Constructs a new ISO 7816-4 CASE 1 CommandAPDU.
CommandAPDU(byte cla, byte ins, byte p1, byte p2, byte[] data)
          Constructs a new ISO 7816-4 CASE 3 CommandAPDU.
CommandAPDU(byte cla, byte ins, byte p1, byte p2, byte[] data, int le)
          Constructs a new ISO 7816-4 CASE 4 CommandAPDU.
CommandAPDU(byte cla, byte ins, byte p1, byte p2, int le)
          Constructs a new ISO 7816-4 CASE 2 CommandAPDU.
 
Method Summary
 byte[] getBuffer()
          Gets the internal CommandAPDU buffer.
 byte getByte(int index)
          Gets the byte at the specified position in the buffer.
 byte[] getBytes()
          Gets a byte array of the buffered CommandAPDU.
 byte getCLA()
          Gets the CLA byte value.
 byte getINS()
          Gets the INS byte value.
 int getLC()
          Gets the length of data field (LC).
 int getLE()
          Gets the expected length of ResponseAPDU (LE).
 int getLength()
          Gets the length of the buffered CommandAPDU.
 byte getP1()
          Gets the first parameter (P1) byte value.
 byte getP2()
          Gets the second parameter (P2) byte value.
 void setByte(int index, byte value)
          Sets the byte value at the specified position in the buffer.
 java.lang.String toString()
          Gets a string representation of this CommandAPDU.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLA

public static final int CLA
Constant for addressing CLA in the CommandAPDU buffer.

INS

public static final int INS
Constant for addressing INS in the CommandAPDU buffer.

P1

public static final int P1
Constant for addressing P1 in the CommandAPDU buffer.

P2

public static final int P2
Constant for addressing P2 in the CommandAPDU buffer.

LC

public static final int LC
Constant for addressing LC in the CommandAPDU buffer.
Constructor Detail

CommandAPDU

public CommandAPDU(byte[] buffer)
Constructs a new ISO 7816-4 CommandAPDU.
Parameters:
buffer - the entire CommandAPDU as a byte array .

CommandAPDU

public CommandAPDU(byte cla,
                   byte ins,
                   byte p1,
                   byte p2)
Constructs a new ISO 7816-4 CASE 1 CommandAPDU.
Parameters:
cla - CLA byte.
ins - INS byte.
p1 - Parameter byte P1.
p2 - Parameter byte P2.

CommandAPDU

public CommandAPDU(byte cla,
                   byte ins,
                   byte p1,
                   byte p2,
                   int le)
Constructs a new ISO 7816-4 CASE 2 CommandAPDU.
Parameters:
cla - CLA byte.
ins - INS byte.
p1 - Parameter byte P1.
p2 - Parameter byte P2.
le - Length of expected ResponseAPDU. This value can be in the range of -1 to 255, where -1 means no length is expected and 0 means the maximum length supported is expected.

CommandAPDU

public CommandAPDU(byte cla,
                   byte ins,
                   byte p1,
                   byte p2,
                   byte[] data)
Constructs a new ISO 7816-4 CASE 3 CommandAPDU.
Parameters:
cla - CLA byte.
ins - INS byte.
p1 - Parameter byte P1.
p2 - Parameter byte P2.
data - The CommandAPDU data as a byte array. The length LC is derived from the array length.

CommandAPDU

public CommandAPDU(byte cla,
                   byte ins,
                   byte p1,
                   byte p2,
                   byte[] data,
                   int le)
Constructs a new ISO 7816-4 CASE 4 CommandAPDU.
Parameters:
cla - CLA byte.
ins - INS byte.
p1 - Parameter byte P1.
p2 - Parameter byte P2.
data - The CommandAPDU data as a byte array. The length LC is derived from the array length.
le - Length of expected ResponseAPDU. This value can be in the range of -1 to 255, where -1 means no length is expected and 0 means the maximum length supported is expected.
Method Detail

getCLA

public byte getCLA()
Gets the CLA byte value.
Returns:
CLA byte of the CommandAPDU.

getINS

public byte getINS()
Gets the INS byte value.
Returns:
INS byte of the CommandAPDU

getP1

public byte getP1()
Gets the first parameter (P1) byte value.
Returns:
P1 byte of the CommandAPDU

getP2

public byte getP2()
Gets the second parameter (P2) byte value.
Returns:
P2 byte of the CommandAPDU

getLC

public int getLC()
Gets the length of data field (LC).
Returns:
The number of bytes present in the data field of the CommandAPDU. The value 0 indicates that there is no body.

getLE

public int getLE()
Gets the expected length of ResponseAPDU (LE).
Returns:
The maximum number of bytes expected in the data field of the ResponseAPDU. The value -1 indicates that no value is specified.

getBuffer

public final byte[] getBuffer()
Gets the internal CommandAPDU buffer. This method allows user to manipulate the buffered CommandAPDU.
Returns:
buffer that holds the current CommandAPDU
See Also:
getBytes()

getByte

public final byte getByte(int index)
Gets the byte at the specified position in the buffer. This method can only be used to access the CommandAPDU currently stored. It is not possible to read beyond the end of the CommandAPDU.
Parameters:
index - the position in the buffer
Returns:
the value at the given position, or -1 if the position is invalid
See Also:
setByte(int, byte), getLength()

getBytes

public final byte[] getBytes()
Gets a byte array of the buffered CommandAPDU. The byte array returned gets allocated with the exact size of the buffered CommandAPDU. To get direct access to the internal buffer, use getBuffer().
Returns:
the buffered CommandAPDU copied into a new array
See Also:
getBuffer()

getLength

public final int getLength()
Gets the length of the buffered CommandAPDU.
Returns:
the length of the CommandAPDU currently stored

setByte

public final void setByte(int index,
                          byte value)
Sets the byte value at the specified position in the buffer. This method can only be used to modify an CommandAPDU already stored. It is not possible to set bytes beyond the end of the current CommandAPDU.
Parameters:
index - the position in the buffer
value - the new byte value to store
See Also:
getByte(int), getLength()

toString

public java.lang.String toString()
Gets a string representation of this CommandAPDU.
Overrides:
toString in class java.lang.Object
Returns:
a string describing this CommandAPDU.