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
  • data is an optional byte array of data received from the smart card.
  • SW1 is the status byte 1 containing command processing status.
  • SW2 is the status byte 2 containing command processing qualifier.

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); 

Additional information

http://www.opencard.org
See Also:
  • CommandAPDU
  • invalid reference
    com.dalsemi.onewire.container.OneWireContainer16
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected byte[]
    byte array containing the entire ResponseAPDU
    protected int
    length of this ResponseAPDU currently in the apduBuffer
  • Constructor Summary

    Constructors
    Constructor
    Description
    ResponseAPDU(byte[] buffer)
    Constructs a new ResponseAPDU with the given buffer byte array.
  • Method Summary

    Modifier and Type
    Method
    Description
    final byte
    getByte(int index)
    Gets the byte value at the specified offset in apduBuffer.
    final byte[]
    Gets a byte array holding this ResponseAPDU apduBuffer.
    byte[]
    Gets the data field of this ResponseAPDU.
    final int
    Gets the length of apduBuffer.
    final int
    Gets the value of SW1 and SW2 as an integer.
    final byte
    Gets the value of SW1.
    final byte
    Gets the value of SW2.
    Gets a string representation of this ResponseAPDU.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • apduBuffer

      protected byte[] apduBuffer
      byte array containing the entire ResponseAPDU
    • apduLength

      protected int apduLength
      length of this ResponseAPDU currently in the apduBuffer
  • Constructor Details

    • 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 invalid input: '<' 2.
      See Also:
  • Method Details

    • 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 invalid input: '<'invalid input: '<' 8) invalid input: '&' 0xFF00) | (SW2 invalid input: '&' 0xFF))
      Returns:
      (((SW1 invalid input: '<'invalid input: '<' 8) invalid input: '&' 0xFF00) | (SW2 invalid input: '&' 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

      public final byte[] getBytes()
      Gets a byte array holding this ResponseAPDU apduBuffer.
      Returns:
      apduBuffer copied into a new array
      See Also:
    • 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