com.acs.smartcard
Class Reader

java.lang.Object
  extended by com.acs.smartcard.Reader

public class Reader
extends java.lang.Object

This class represents a smart card reader attached to the android device.


Nested Class Summary
static interface Reader.OnStateChangeListener
          Interface definition for a callback to be invoked when the state of reader is changed.
 
Field Summary
static int CARD_ABSENT
          There is no card in the reader.
static int CARD_COLD_RESET
          Cycle power and reset the card.
static int CARD_NEGOTIABLE
          The card has been reset and is awaiting PTS negotiation.
static int CARD_POWER_DOWN
          Power down the card.
static int CARD_POWERED
          Power is being provided to the card, but the library is unaware of the mode of the card.
static int CARD_PRESENT
          There is a card in the reader, but it has not been moved into position for use.
static int CARD_SPECIFIC
          The card has been reset and specific communication protocols have been established.
static int CARD_SWALLOWED
          There is a card in the reader in position for use.
static int CARD_UNKNOWN
          The library is unaware of the current state of the reader.
static int CARD_WARM_RESET
          Force a reset on the card.
static int IOCTL_ACR128_READER_COMMAND
          Control code for sending command to ACR128 reader.
static int IOCTL_ACR83_DISPLAY_LCD_MESSAGE
          Control code for displaying LCD message on ACR83/APG8201 reader.
static int IOCTL_ACR83_GET_FIRMWARE_VERSION
          Control code for getting firmware version from ACR83/APG8201 reader.
static int IOCTL_ACR83_READ_KEY
          Control code for reading key from ACR83/APG8201 reader.
static int IOCTL_CCID_ESCAPE
          Control code for sending escape command to the reader.
static int IOCTL_GET_FEATURE_REQUEST
          Control code for getting supported features (PC/SC 2.0 Part 10).
static int PROTOCOL_DEFAULT
          Use the default transmission parameters or card clock frequency.
static int PROTOCOL_OPTIMAL
          Use optimal transmission parameters or card clock frequency.
static int PROTOCOL_RAW
          Raw is the active protocol.
static int PROTOCOL_T0
          T=0 is the active protocol.
static int PROTOCOL_T1
          T=1 is the active protocol.
static int PROTOCOL_TX
          This is the mask of ISO defined transmission protocols.
static int PROTOCOL_UNDEFINED
          There is no active protocol.
 
Constructor Summary
Reader(android.hardware.usb.UsbManager manager)
          Creates an instance of Reader.
 
Method Summary
 void close()
          Closes the reader.
 int control(int slotNum, int controlCode, byte[] inBuffer, int inBufferLength, byte[] outBuffer, int outBufferLength)
          Controls the reader.
 byte[] getAtr(int slotNum)
          Gets the ATR string.
 android.hardware.usb.UsbDevice getDevice()
          Gets the device.
 int getNumSlots()
          Gets the number of slots.
 int getProtocol(int slotNum)
          Gets the active protocol.
 java.lang.String getReaderName()
          Gets the reader name.
 int getState(int slotNum)
          Gets the card state.
 boolean isOpened()
          Returns true if the reader is opened.
 boolean isSupported(android.hardware.usb.UsbDevice device)
          Returns true if the reader is supported.
 void open(android.hardware.usb.UsbDevice device)
          Opens the reader.
 byte[] power(int slotNum, int action)
          Performs the power action on the card.
 void setOnStateChangeListener(Reader.OnStateChangeListener listener)
          Registers a callback to be invoked when the state of reader is changed.
 int setProtocol(int slotNum, int preferredProtocols)
          Sets the protocol.
 int transmit(int slotNum, byte[] sendBuffer, int sendBufferLength, byte[] recvBuffer, int recvBufferLength)
          Transmits the APDU.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CARD_POWER_DOWN

public static final int CARD_POWER_DOWN
Power down the card.

See Also:
Constant Field Values

CARD_COLD_RESET

public static final int CARD_COLD_RESET
Cycle power and reset the card.

See Also:
Constant Field Values

CARD_WARM_RESET

public static final int CARD_WARM_RESET
Force a reset on the card.

See Also:
Constant Field Values

PROTOCOL_UNDEFINED

public static final int PROTOCOL_UNDEFINED
There is no active protocol.

See Also:
Constant Field Values

PROTOCOL_T0

public static final int PROTOCOL_T0
T=0 is the active protocol.

See Also:
Constant Field Values

PROTOCOL_T1

public static final int PROTOCOL_T1
T=1 is the active protocol.

See Also:
Constant Field Values

PROTOCOL_RAW

public static final int PROTOCOL_RAW
Raw is the active protocol.

See Also:
Constant Field Values

PROTOCOL_TX

public static final int PROTOCOL_TX
This is the mask of ISO defined transmission protocols.

See Also:
Constant Field Values

PROTOCOL_DEFAULT

public static final int PROTOCOL_DEFAULT
Use the default transmission parameters or card clock frequency.

See Also:
Constant Field Values

PROTOCOL_OPTIMAL

public static final int PROTOCOL_OPTIMAL
Use optimal transmission parameters or card clock frequency. This is the default.

See Also:
Constant Field Values

CARD_UNKNOWN

public static final int CARD_UNKNOWN
The library is unaware of the current state of the reader.

See Also:
Constant Field Values

CARD_ABSENT

public static final int CARD_ABSENT
There is no card in the reader.

See Also:
Constant Field Values

CARD_PRESENT

public static final int CARD_PRESENT
There is a card in the reader, but it has not been moved into position for use.

See Also:
Constant Field Values

CARD_SWALLOWED

public static final int CARD_SWALLOWED
There is a card in the reader in position for use. The card is not powered.

See Also:
Constant Field Values

CARD_POWERED

public static final int CARD_POWERED
Power is being provided to the card, but the library is unaware of the mode of the card.

See Also:
Constant Field Values

CARD_NEGOTIABLE

public static final int CARD_NEGOTIABLE
The card has been reset and is awaiting PTS negotiation.

See Also:
Constant Field Values

CARD_SPECIFIC

public static final int CARD_SPECIFIC
The card has been reset and specific communication protocols have been established.

See Also:
Constant Field Values

IOCTL_CCID_ESCAPE

public static final int IOCTL_CCID_ESCAPE
Control code for sending escape command to the reader.

See Also:
Constant Field Values

IOCTL_ACR128_READER_COMMAND

public static final int IOCTL_ACR128_READER_COMMAND
Control code for sending command to ACR128 reader.

See Also:
Constant Field Values

IOCTL_ACR83_GET_FIRMWARE_VERSION

public static final int IOCTL_ACR83_GET_FIRMWARE_VERSION
Control code for getting firmware version from ACR83/APG8201 reader.

Since:
1.1
See Also:
Constant Field Values

IOCTL_ACR83_DISPLAY_LCD_MESSAGE

public static final int IOCTL_ACR83_DISPLAY_LCD_MESSAGE
Control code for displaying LCD message on ACR83/APG8201 reader.

Since:
1.1
See Also:
Constant Field Values

IOCTL_ACR83_READ_KEY

public static final int IOCTL_ACR83_READ_KEY
Control code for reading key from ACR83/APG8201 reader.

Since:
1.1
See Also:
Constant Field Values

IOCTL_GET_FEATURE_REQUEST

public static final int IOCTL_GET_FEATURE_REQUEST
Control code for getting supported features (PC/SC 2.0 Part 10).

Since:
1.1
See Also:
Constant Field Values
Constructor Detail

Reader

public Reader(android.hardware.usb.UsbManager manager)
Creates an instance of Reader.

Parameters:
manager - the USB manager.
Method Detail

isSupported

public boolean isSupported(android.hardware.usb.UsbDevice device)
Returns true if the reader is supported.

Parameters:
device - the USB device.
Returns:
true or false.

open

public void open(android.hardware.usb.UsbDevice device)
Opens the reader.

Parameters:
device - the USB device.

close

public void close()
Closes the reader.


isOpened

public boolean isOpened()
Returns true if the reader is opened.

Returns:
true or false.

getDevice

public android.hardware.usb.UsbDevice getDevice()
Gets the device.

Returns:
the device.

getNumSlots

public int getNumSlots()
Gets the number of slots.

Returns:
the number of slots.

getReaderName

public java.lang.String getReaderName()
Gets the reader name.

Returns:
the reader name.

setOnStateChangeListener

public void setOnStateChangeListener(Reader.OnStateChangeListener listener)
Registers a callback to be invoked when the state of reader is changed.

Parameters:
listener - the callback that will run.

power

public byte[] power(int slotNum,
                    int action)
             throws ReaderException
Performs the power action on the card.

Parameters:
slotNum - the slot number.
action - the action to be performed on the card: CARD_POWER_DOWN, CARD_COLD_RESET or CARD_WARM_RESET.
Returns:
the ATR string.
Throws:
ReaderException - if the reader is not opened or the reader is failed to perform the power action on the card.

getAtr

public byte[] getAtr(int slotNum)
Gets the ATR string.

Parameters:
slotNum - the slot number.
Returns:
the ATR string.

setProtocol

public int setProtocol(int slotNum,
                       int preferredProtocols)
                throws ReaderException
Sets the protocol.

Parameters:
slotNum - the slot number.
preferredProtocols - the preferred protocols. It can be combined with OR operation. For example, PROTOCOL_T0 | PROTOCOL_T1.
Returns:
the active protocol. Either PROTOCOL_T0 or PROTOCOL_T1.
Throws:
ReaderException - if the reader is failed to set protocol.

getProtocol

public int getProtocol(int slotNum)
Gets the active protocol.

Parameters:
slotNum - the slot number.
Returns:
the active protocol. PROTOCOL_UNDEFINED, PROTOCOL_T0 or PROTOCOL_T1.

getState

public int getState(int slotNum)
Gets the card state.

Parameters:
slotNum - the slot number.
Returns:
the card state. CARD_ABSENT, CARD_PRESENT, CARD_SWALLOWED, CARD_POWERED, CARD_NEGOTIABLE or CARD_SPECIFIC.

transmit

public int transmit(int slotNum,
                    byte[] sendBuffer,
                    int sendBufferLength,
                    byte[] recvBuffer,
                    int recvBufferLength)
             throws ReaderException
Transmits the APDU.

Parameters:
slotNum - the slot number.
sendBuffer - the send buffer.
sendBufferLength - the send buffer length.
recvBuffer - the receive buffer.
recvBufferLength - the receive buffer length.
Returns:
the number of bytes received.
Throws:
ReaderException - if the reader is not opened or the reader is failed to transmit the APDU.

control

public int control(int slotNum,
                   int controlCode,
                   byte[] inBuffer,
                   int inBufferLength,
                   byte[] outBuffer,
                   int outBufferLength)
            throws ReaderException
Controls the reader.

Parameters:
slotNum - the slot number.
controlCode - the control code.
inBuffer - the input buffer.
inBufferLength - the input buffer length.
outBuffer - the output buffer.
outBufferLength - the output buffer length.
Returns:
the number of bytes received.
Throws:
ReaderException - if the reader is not opened or the reader does not accept the control.


Copyright © 2011-2012 Advanced Card Systems Ltd. All Rights Reserved.