Dallas Semiconductor 1-Wire API 1.00 Alpha: Class CommandAPDU

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.dalsemi.onewire.container
Class CommandAPDU

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

public class CommandAPDU
extends 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

- `CLA` is the class byte
- `INS` is the instruction byte
- `P1` is the first parameter byte
- `P2` is the second parameter byte
- `LC` is the number of bytes present in the data block
- `DATA` is an byte array of data to be sent
- `LE` is the maximum number of bytes expected in the `ResponseAPDU`
- `[ ]` denotes optional fields

### Usage

1. `

          byte[] buffer = {(byte)0x90, (byte)0x00, (byte)0x00, (byte)0x00,
                           (byte)0x01, (byte)0x02, (byte)0x03};
          CommandAPDU capdu = new CommandAPDU(buffer);

   `
2. `

          CommandAPDU capdu = new CommandAPDU((byte)0x90, (byte)0x00, (byte)0x00, (byte)0x00,
                                              (byte)0x01, (byte)0x02, (byte)0x03);

   `

### Additonal information

  http://www.opencard.org

Version:
  0.00, 28 Aug 2000
See Also:
  `ResponseAPDU`, `OneWireContainer16`

Field Summary
`static int` | `CLA` Index for addressing `CLA` in this `CommandAPDU` `apduBuffer`.
`static int` | `INS` Index for addressing `INS` in this `CommandAPDU` `apduBuffer`.
`static int` | `LC` Index for addressing `LC` in this `CommandAPDU` `apduBuffer`.
`static int` | `P1` Index for addressing `P1` in this `CommandAPDU` `apduBuffer`.
`static int` | `P2` Index for addressing `P2` in this `CommandAPDU` `apduBuffer`.

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 this `CommandAPDU` `apduBuffer`.
`byte` | `getByte(int index)` Gets the byte at the specified offset in the `apduBuffer`.
`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 offset in the `apduBuffer`.
`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

  Index for addressing `CLA` in this `CommandAPDU` `apduBuffer`.

### INS

    public static final int INS

  Index for addressing `INS` in this `CommandAPDU` `apduBuffer`.

### P1

    public static final int P1

  Index for addressing `P1` in this `CommandAPDU` `apduBuffer`.

### P2

    public static final int P2

  Index for addressing `P2` in this `CommandAPDU` `apduBuffer`.

### LC

    public static final int LC

  Index for addressing `LC` in this `CommandAPDU` `apduBuffer`.

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`, ranges from `-1` to `255`, where `-1` is no length and `0` is the maximum length supported
  See Also:
    `ResponseAPDU`

### 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` - this `CommandAPDU` 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 4 `CommandAPDU`.
  Parameters:
    `cla` - `CLA` byte
    `ins` - `INS` byte
    `p1` - parameter byte `P1`
    `p2` - parameter byte `P2`
    `data` - `CommandAPDU` data as a byte array, `LC` is derived from this data array length
    `le` - length of expected `ResponseAPDU`, ranges from `-1` to `255`, where `-1` is no length and `0` is the maximum length supported
  See Also:
    `ResponseAPDU`

Method Detail

### getCLA

    public byte getCLA()

  Gets the `CLA` byte value.
  Returns:
    `CLA` byte of this `CommandAPDU`

### getINS

    public byte getINS()

  Gets the `INS` byte value.
  Returns:
    `INS` byte of this `CommandAPDU`

### getP1

    public byte getP1()

  Gets the first parameter (`P1`) byte value.
  Returns:
    `P1` byte of this `CommandAPDU`

### getP2

    public byte getP2()

  Gets the second parameter (`P2`) byte value.
  Returns:
    `P2` byte of this `CommandAPDU`

### 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 of `ResponseAPDU` (`LE`).
  Returns:
    the maximum number of bytes expected in the data field of the `ResponseAPDU` to this `CommandAPDU`, `-1` indicates that no value is specified
  See Also:
    `ResponseAPDU`

### getBuffer

    public final byte[] getBuffer()

  Gets this `CommandAPDU` `apduBuffer`. This method allows user to manipulate the buffered `CommandAPDU`.
  Returns:
    `apduBuffer` that holds the current `CommandAPDU`
  See Also:
    `getBytes()`

### getByte

    public final byte getByte(int index)

  Gets the byte at the specified offset in the `apduBuffer`. 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 offset in the `apduBuffer`
  Returns:
    the value at the given offset, or `-1` if the offset 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 `apduBuffer`, 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 offset in the `apduBuffer`. This method can only be used to modify a `CommandAPDU` already stored. It is not possible to set bytes beyond the end of the current `CommandAPDU`.
  Parameters:
    `index` - the offset in the `apduBuffer`
    `value` - the new byte value to store
  See Also:
    `getByte(int)`, `getLength()`

### toString

    public String toString()

  Gets a string representation of this `CommandAPDU`.
  Overrides:
    `toString` in class `Object`
  Returns:
    a string describing this `CommandAPDU`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD