com.dalsemi.onewire.container
Class ResponseAPDU

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

public class ResponseAPDU
extends Object

A ResponseAPDU represents an Application Protocol Data Unit (APDU) received from the smart card in response to a previous CommandAPDU. A ResponseAPDU consists of an optional body and a mandatory Status Word (SW).

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

          DATA   |  STATUS WORD
         [data]  |  SW1     SW2 
where

Usage

  1.    byte[] buffer = {(byte)0x01, (byte)0x02, (byte)0x90, (byte)0x00};
       ResponseAPDU rapdu = new ResponseAPDU(buffer); 
  2.    OneWireContainer16 owc16 = new OneWireContainer16(adapter, address);
       byte[] buffer = {(byte)0x90, (byte)0x00, (byte)0x00, (byte)0x00, 
                        (byte)0x01, (byte)0x02, (byte)0x03};
       CommandAPDU capdu = new CommandAPDU(buffer);
       ResponseAPDU rapdu = owc16.sendAPDU(capdu, runTime); 

Additonal information

http://www.opencard.org

Version:
0.00, 28 Aug 2000
See Also:
CommandAPDU, OneWireContainer16

Constructor Summary
ResponseAPDU(byte[] buffer)
          Constructs a new ResponseAPDU with the given buffer byte array.
 
Method Summary
 byte getByte(int index)
          Gets the byte value at the specified offset in apduBuffer.
 byte[] getBytes()
          Gets a byte array holding this ResponseAPDU apduBuffer.
 byte[] getData()
          Gets the data field of this ResponseAPDU.
 int getLength()
          Gets the length of apduBuffer.
 int getSW()
          Gets the value of SW1 and SW2 as an integer.
 byte getSW1()
          Gets the value of SW1.
 byte getSW2()
          Gets the value of SW2.
 String toString()
          Gets a string representation of this ResponseAPDU.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResponseAPDU

public ResponseAPDU(byte[] buffer)
Constructs a new ResponseAPDU with the given buffer byte array. The internal apduLength is set to the length of the buffer passed.
Parameters:
buffer - the byte array with data for the internal apduBuffer
Throws:
RuntimeException - thrown when buffer length < 2.
See Also:
CommandAPDU
Method Detail

getData

public byte[] getData()
Gets the data field of this ResponseAPDU.
Returns:
a byte array containing this ResponseAPDU data field

getSW

public final int getSW()
Gets the value of SW1 and SW2 as an integer. It is computed as:

(((SW1 << 8) & 0xFF00) | (SW2 & 0xFF))
Returns:
(((SW1 << 8) & 0xFF00) | (SW2 & 0xFF)) as an integer

getSW1

public final byte getSW1()
Gets the value of SW1.
Returns:
value of SW1 as a byte

getSW2

public final byte getSW2()
Gets the value of SW2.
Returns:
value of SW2 as a byte

getByte

public final byte getByte(int index)
Gets the byte value at the specified offset in apduBuffer.
Parameters:
index - the offset in the apduBuffer
Returns:
the value at the given offset, or -1 if the offset is invalid
See Also:
getBytes(), getLength()

getBytes

public final byte[] getBytes()
Gets a byte array holding this ResponseAPDU apduBuffer.
Returns:
apduBuffer copied into a new array
See Also:
getByte(int), getLength()

getLength

public final int getLength()
Gets the length of apduBuffer.
Returns:
apduLength the length of the apduBuffer currently stored

toString

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