Package com.dalsemi.onewire.container
Class CommandAPDU
java.lang.Object
com.dalsemi.onewire.container.CommandAPDU
A
According to ISO 7816-4, 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
CLA
is the class byteINS
is the instruction byteP1
is the first parameter byteP2
is the second parameter byteLC
is the number of bytes present in the data blockDATA
is an byte array of data to be sentLE
is the maximum number of bytes expected in theResponseAPDU
[ ]
denotes optional fields
Usage
byte[] buffer = { (byte) 0x90, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03 }; CommandAPDU capdu = new CommandAPDU(buffer);
CommandAPDU capdu = new CommandAPDU((byte) 0x90, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03);
Additional information
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected byte[]
Byte array containing the entireCommandAPDU
.protected int
Length of thisCommandAPDU
currently in theapduBuffer
.static final int
Index for addressingCLA
in thisCommandAPDU
apduBuffer
.static final int
Index for addressingINS
in thisCommandAPDU
apduBuffer
.static final int
Index for addressingLC
in thisCommandAPDU
apduBuffer
.static final int
Index for addressingP1
in thisCommandAPDU
apduBuffer
.static final int
Index for addressingP2
in thisCommandAPDU
apduBuffer
. -
Constructor Summary
ConstructorDescriptionCommandAPDU
(byte[] buffer) Constructs a new ISO 7816-4CommandAPDU
.CommandAPDU
(byte cla, byte ins, byte p1, byte p2) Constructs a new ISO 7816-4 CASE 1CommandAPDU
.CommandAPDU
(byte cla, byte ins, byte p1, byte p2, byte[] data) Constructs a new ISO 7816-4 CASE 3CommandAPDU
.CommandAPDU
(byte cla, byte ins, byte p1, byte p2, byte[] data, int le) Constructs a new ISO 7816-4 CASE 4CommandAPDU
.CommandAPDU
(byte cla, byte ins, byte p1, byte p2, int le) Constructs a new ISO 7816-4 CASE 2CommandAPDU
. -
Method Summary
Modifier and TypeMethodDescriptionfinal byte[]
Gets thisCommandAPDU
apduBuffer
.final byte
getByte
(int index) Gets the byte at the specified offset in theapduBuffer
.final byte[]
getBytes()
Gets a byte array of the bufferedCommandAPDU
.byte
getCLA()
Gets theCLA
byte value.byte
getINS()
Gets theINS
byte value.int
getLC()
Gets the length of data field (LC
).int
getLE()
Gets the expected length ofResponseAPDU
(LE
).final int
Gets the length of the bufferedCommandAPDU
.byte
getP1()
Gets the first parameter (P1
) byte value.byte
getP2()
Gets the second parameter (P2
) byte value.final void
setByte
(int index, byte value) Sets the byte value at the specified offset in theapduBuffer
.toString()
Gets a string representation of thisCommandAPDU
.
-
Field Details
-
CLA
public static final int CLAIndex for addressingCLA
in thisCommandAPDU
apduBuffer
.- See Also:
-
INS
public static final int INSIndex for addressingINS
in thisCommandAPDU
apduBuffer
.- See Also:
-
P1
public static final int P1Index for addressingP1
in thisCommandAPDU
apduBuffer
.- See Also:
-
P2
public static final int P2Index for addressingP2
in thisCommandAPDU
apduBuffer
.- See Also:
-
LC
public static final int LCIndex for addressingLC
in thisCommandAPDU
apduBuffer
.- See Also:
-
apduBuffer
protected byte[] apduBufferByte array containing the entireCommandAPDU
. -
apduLength
protected int apduLengthLength of thisCommandAPDU
currently in theapduBuffer
.
-
-
Constructor Details
-
CommandAPDU
public CommandAPDU(byte[] buffer) Constructs a new ISO 7816-4CommandAPDU
.- Parameters:
buffer
- the entireCommandAPDU
as a byte array
-
CommandAPDU
public CommandAPDU(byte cla, byte ins, byte p1, byte p2) Constructs a new ISO 7816-4 CASE 1CommandAPDU
.- Parameters:
cla
-CLA
byteins
-INS
bytep1
- parameter byteP1
p2
- parameter byteP2
-
CommandAPDU
public CommandAPDU(byte cla, byte ins, byte p1, byte p2, int le) Constructs a new ISO 7816-4 CASE 2CommandAPDU
.- Parameters:
cla
-CLA
byteins
-INS
bytep1
- parameter byteP1
p2
- parameter byteP2
le
- length of expectedResponseAPDU
, ranges from-1
to255
, where-1
is no length and0
is the maximum length supported- See Also:
-
CommandAPDU
public CommandAPDU(byte cla, byte ins, byte p1, byte p2, byte[] data) Constructs a new ISO 7816-4 CASE 3CommandAPDU
.- Parameters:
cla
-CLA
byteins
-INS
bytep1
- parameter byteP1
p2
- parameter byteP2
data
- thisCommandAPDU
data as a byte array,LC
is derived from this data array length
-
CommandAPDU
public CommandAPDU(byte cla, byte ins, byte p1, byte p2, byte[] data, int le) Constructs a new ISO 7816-4 CASE 4CommandAPDU
.- Parameters:
cla
-CLA
byteins
-INS
bytep1
- parameter byteP1
p2
- parameter byteP2
data
-CommandAPDU
data as a byte array,LC
is derived from this data array lengthle
- length of expectedResponseAPDU
, ranges from-1
to255
, where-1
is no length and0
is the maximum length supported- See Also:
-
-
Method Details
-
getCLA
public byte getCLA()Gets theCLA
byte value.- Returns:
CLA
byte of thisCommandAPDU
-
getINS
public byte getINS()Gets theINS
byte value.- Returns:
INS
byte of thisCommandAPDU
-
getP1
public byte getP1()Gets the first parameter (P1
) byte value.- Returns:
P1
byte of thisCommandAPDU
-
getP2
public byte getP2()Gets the second parameter (P2
) byte value.- Returns:
P2
byte of thisCommandAPDU
-
getLC
public int getLC()Gets the length of data field (LC
).- Returns:
- the number of bytes present in the data field of this
CommandAPDU
,0
indicates that there is no body
-
getLE
public int getLE()Gets the expected length ofResponseAPDU
(LE
).- Returns:
- the maximum number of bytes expected in the data field of the
ResponseAPDU
to thisCommandAPDU
,-1
indicates that no value is specified - See Also:
-
getBuffer
public final byte[] getBuffer()Gets thisCommandAPDU
apduBuffer
. This method allows user to manipulate the bufferedCommandAPDU
.- Returns:
apduBuffer
that holds the currentCommandAPDU
- See Also:
-
getByte
public final byte getByte(int index) Gets the byte at the specified offset in theapduBuffer
. This method can only be used to access theCommandAPDU
currently stored. It is not possible to read beyond the end of theCommandAPDU
.- Parameters:
index
- the offset in theapduBuffer
- Returns:
- the value at the given offset, or
-1
if the offset is invalid - See Also:
-
getBytes
public final byte[] getBytes()Gets a byte array of the bufferedCommandAPDU
. The byte array returned gets allocated with the exact size of the bufferedCommandAPDU
. To get direct access to the internalapduBuffer
, usegetBuffer()
.- Returns:
- the buffered
CommandAPDU
copied into a new array - See Also:
-
getLength
public final int getLength()Gets the length of the bufferedCommandAPDU
.- Returns:
- the length of the
CommandAPDU
currently stored
-
setByte
public final void setByte(int index, byte value) Sets the byte value at the specified offset in theapduBuffer
. This method can only be used to modify aCommandAPDU
already stored. It is not possible to set bytes beyond the end of the currentCommandAPDU
.- Parameters:
index
- the offset in theapduBuffer
value
- the new byte value to store- See Also:
-
toString
Gets a string representation of thisCommandAPDU
.
-