IccManager

##
android.device
Class IccManager

    java.lang.Object
      android.device.IccManager

    public class IccManager

extends java.lang.Object

The IccManager class is used to initialize and control the smart card reader, to sends a command Application Protocol Data Unit(APDU) to a card and retrieve the response APDU.

To control the smart card reader with this class, according to the following steps,

1. You can obtain an instance of this class by calling `IccManager`.

   IccManager manager = new IccManager();

2. Initialize a slot for the smart card reader with `open`.
3. Query whether the smart card is existent with `detect`.
4. Power on to activate and reset the smart card reader with `activate`.
5. Sends a command Application Protocol Data Unit(APDU) to a card and retrieve the response APDU with `apduTransmit`.
6. Power off the smart card reader with `deactivate`.
7. Call `close` to close the slot for smart card reader.

For more information about the smart card reader, read IccManager sample.

Constructor Summary
`IccManager()` The IccManager class is used to initialize and control the smart card reader.

Method Summary
`int` | `open(byte slot, byte CardType, byte Volt)` Open the IC card for operation.
`int` | `close()` Close the slot.
`int` | `detect()` Check if IC card is inserted.
`int` | `activate(byte[] pAtr)` Activate and reset the card.
`int` | `apduTransmit(byte[] apdu, int apduLen, byte[] rsp, byte[] sw)` Transmit APDU to the IC card.
`int` | `deactivate()` Deactivate the card.
`int` | `request_Type(byte[] type)` Request IC Card type.
`int` | `getResponseEnable(byte autoFlag)` Set the drive layer to the 61xx, 6Cxx and other commands for automatic data acquisition. The default for automatic acquisition.
`int` | `setETU(int etuTime)` Set the ETU.
`int` | `sle4442_reset(byte[] pAtr)` reset the SLE4442.
`byte[]` | `sle4442_readMainMemory(int addr, int length)` Read the data stored in main memory for SLE4442.
`int` | `sle4442_writeMainMemory(int addr, byte[] data, int dataLen)` Write data to the main storage area SLE4442.
`byte[]` | `sle4442_readProtectionMemory(int address, int len)` Read SLE4442 card protection bit storage data (4 BYTE). 4 bytes of data read is to save the SLE4442 bits data in storage area.
`int` | `sle4442_writeProtectionMemory(int addr, byte[] data, int dataLen)` The write protection bit storage area.
`int` | `sle4442_verifyPassword(byte[] passwd)` Comparison SLE4442 cards, each card compared to the card password, if all the card data become to read-only, you will not be able to do any write operation.
`int` | `sle4442_changePassword(byte[] passwd)` Change password.
`int` | `sle4442_readErrorCounter(byte[] errorCount)` Read error code value.
`int` | `sle4436_reset(byte[] pAtr)` Reset the SLE4436.
`byte[]` | `sle4436_readMemory(int addr, int length)` Read the data stored in main memory for SLE4436.
`int` | `sle4436_writeMemory(int addr, byte[] data, int dataLen)` Write data to the main storage area SLE4436.
`int` | `sle4436_verifyPassword(byte[] passwd)` Submit the transfer data, enter the personalization mode.
`int` | `sle4436_regIncrease(int shiftBits)` Move the register.
`int` | `sle4436_readBit(byte[] pData)` Read values from the card bit.
`int` | `sle4436_writeBit()` Write a bit for card.
`int` | `sle4436_reloadByte()` Reload Byte.
`int` | `sle4436_decValue(int pValue)` Reduction balance.
`int` | `sle4428_reset(byte[] pAtr)` Reset the SLE4428.
`byte[]` | `sle4428_readMemory(int addr, int length)` Read the data stored in main memory for SLE4428.
`int` | `sle4428_writeMemory(int addr, byte[] data, int dataLen)` Write data to the main storage area SLE4428.
`int` | `sle4428_password(int mode, byte[] data)` Submit the transfer data, enter the personalization mode.
`byte[]` | `at88sc102_read(int addr, int length)` Read the data stored in main memory for At88sc102.
`int` | `at88sc102_write(int addr, byte[] data, int dataLen)` Write data to the main storage area At88sc102.
`int` | `at88sc102_VerifyPassword(int type, byte[] data, int length)` Check & Verify password for At88sc102.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### IccManager

    public IccManager()

Method Detail

### open

    public int open(byte slot,
                    byte CardType,
                    byte Volt)

  Open the IC card for operation.

  Parameters:
    `slot` - Card slot type:
    0 : IC slot
    1 : PSAM1 slot
    2 : PSAM2 slot
    `CardType` - Card type:
    0x01 : IC card
    0x02 : SLE4442
    `Volt` - valtage to supply:
    0x01 : 3V
    0x02 : 5V
    0x03 : 1.8V
  Returns:
    0 if successful, negative number if not successful.
  Example:
    If you initialize the IC card with 3 voltage, you can:
    `IccManager mIccReader = new IccManager();
    public static final byte SLOT_IC = 0x00;
    public static final byte TYPE_IC = 0x01;
    public static final byte VOLT_3 = 0x01;
    int ret = mIccReader.open(SLOT_IC, TYPE_IC, VOLT_3);
    if(ret < 0) {
    //open failed
    }`

### close

    public int close()

  Close the slot.

  Parameters:
    none
  Returns:
    0 if successful, negative number if not successful.
  Example:
    `int ret = mIccReader.open(SLOT_IC, TYPE_IC, VOLT_3);
    if(ret == 0) {
    mIccReader.close();
    }`

### detect

    public int detect()

  Check if IC card is inserted.

  Parameters:
    none
  Returns:
    0 card is detected, negative number if card is not detected.
  Example:
    `mIccReader.open(SLOT_IC, TYPE_IC, VOLT_3);
    int ret = mIccReader.detect();
    if(ret == 0)
    //card is detected
    else
    //card is not detected`

### activate

    public int activate(byte[] pAtr)

  Activate and reset the card.

  Parameters:
    `pAtr` - To store the returned ATR from the card.
  Returns:
    0 if successful, negative number if failed.
  Example:
    `int ret = mIccReader.detect();
    if(ret == 0) {
    byte[] atr = new byte[64];
    int re = mIccReader.activate(atr);
    if(re == 0)
    //activate success
    else
    //activate failed
    }`

### apduTransmit

    public int apduTransmit(byte[] apdu,
                            int apduLen,
                            byte[] rsp,
                            byte[] sw)

  Transmit APDU to the IC card.

  Parameters:
    `apdu` - APDU to be sent to the card.
    `apduLen` - Length of APDU.
    `rsp` - To store the response from the card.
    `sw` - To store the returned status bytes.
  Returns:
    Length of rsp if successful, negative number if function failed.
  Example:
    `int ret = mIccReader.activate(atr);
    if(ret < 0)
    return; //activate failed
    byte[] apduBuff = {0x00, 0xA4, 0x04, 0x00, 0x0E, 0x31, 0x50, 0x41, 0x59, 0x2E, 0x53,
    0x59, 0x53, 0x2E, 0x44, 0x44, 0x46, 0x30, 0x31, 0x00};
    int apduCount = apduBuff.length;
    byte[] rspBuf = new byte[256];
    byte[] rspStatus = new byte[1];
    int len = mIccReader.ApduTransmit(apduBuff, (char) apduCount, rspBuf, rspStatus);
    if(len < 0)
    //ApduTransmit failed`

### deactivate

    public int deactivate()

  Deactivate the card.

  Parameters:
    none
  Returns:
    0 if successful, negative number if failed.
  Example:
    `int ret = mIccReader.activate(atr);
    if(ret == 0) {
    mIccReader.deactivate();
    }`

### request_Type

    public int request_Type(byte[] type)

  Request IC card type.

  Parameters:
    `type` - To store the type of card:
    1 : IC card
    2 : SLE4442 card
    3 : at88sc_102 card
    4 : at24xx card
    5 : at88sc_1608 card
  Returns:
    0 if successful, others if failed.
  Example:
    `mIccReader.activate(atr);
    public static final byte[] TYPE = 1;
    int ret = mIccReader.request_Type(TYPE);
    if(ret == 0)
    //request_Type success
    else
    //request_Type failed`

### getResponseEnable

    public int getResponseEnable(byte autoFlag)

  Set the drive layer to the 61xx, 6Cxx and other commands for automatic data acquisition. The default is automatic acquisition.

  Parameters:
    `autoFlag` - Value:
    0 : by the application layer to get.
    1 : by the drive layer is automatically acquired.
  Returns:
    0 if successful, negative number if failed.
  Example:
    `mIccReader.activate(atr);
    public static final byte AUTO_FLAG = 1;
    int ret = mIccReader.getResponseEnable(AUTO_FLAG);
    if(ret == 0)
    //getResponseEnable success
    else
    //getResponseEnable failed`

### setETU

    public int setETU(int etuTime)

  Set the ETU. Default is 372.

  Parameters:
    `etuTime` - ETU.
  Returns:
    0 if successful, negative number if not successful.
  Example:
    `mIccReader.activate(atr);
    int etuTime = 373;
    int ret = mIccReader.setETU(etuTime);
    if(ret == 0)
    //setETU success
    else
    //setETU fail`

### sle4442_reset

    public int sle4442_reset(byte[] pAtr)

  Reset the SLE4442.

  Parameters:
    `pAtr` - To store the return ATR.
  Returns:
    Length of ATR, negative number if failed.

### sle4442_readMainMemory

    public byte[] sle4442_readMainMemory(int addr,
                                         int length)

  Read the data stored in main memory for SLE4442.

  Parameters:
    `addr` - The starting address of operation data, the range of the parameters of the SLE4442 card is 0 to 255.
    `length` - To read the data length, the range of the parameters of the SLE4442 card is 1 to 256. ByteAddr and Length cannot be greater than the actual capacity of the card, otherwise the reader will refuse to execute the command and returns an error.
  Returns:
    Byte array indicating the store data if successful, null if failed.

### sle4442_writeMainMemory

    public int sle4442_writeMainMemory(int addr,
                                       byte[] data,
                                       int dataLen)

  Write data to the main storage area SLE4442.

  Parameters:
    `addr` - The starting address of operation data, the range of the parameters of the SLE4442 card is 0 to 255.
    `data` - The data to be written.
    `dataLen` - Length of data.
  Returns:
    0 if successful, -1 if failed.

### sle4442_readProtectionMemory

    public byte[] sle4442_readProtectionMemory(int address,
                                               int len)

  Read SLE4442 card protection bit storage data (4 BYTE). 4 bytes of data read is to save the SLE4442 bits data in storage area. Byte sequence bit: low in front, high in the post. Such as: read data: 30 FF 1F F8 from the first byte of 30H can be analyzed as follows: the binary 30H corresponding to the lower four bits: 00110000 to 0 represent the four byte SLE4442 of the card (answer to reset) cannot be changed.

  Parameters:
    `address` - The parameter range is 0x00 to 0xff.
    `Len` - Length to read, 4 Bytes: bit31 - read out 32Bytes; bit0 - read out 1Byte; bit* - etc.
  Returns:
    Byte array indicating protected storage data if successful, null if failed.

### sle4442_writeProtectionMemory

    public int sle4442_writeProtectionMemory(int addr,
                                             byte[] data,
                                             int dataLen)

  The write protection bit storage area. Write protection on the 4442 card data (disposable, write protection is not able to restore). Behind the 32BYTE data only for SLE4442 write protect (corresponding to protect a storage area of 32 BIT). This function can be one of a plurality of consecutive bytes protection (up to 32 bytes). According to the write protection properties of SLE4442 card, a byte write protection must provide the bytes of data and sends the write protection command, at the same time, consistent data provides the data and the actual store only when the specified storage area is write protected.

  Parameters:
    `addr` - The starting address of operation data, the range of the parameters of the SLE4442 card is 0 to 31.
    `data` - Write protect bit data.
    `dataLen` - Length of data.
  Returns:
    0 if successful, -1 if failed.

### sle4442_verifyPassword

    public int sle4442_verifyPassword(byte[] passwd)

  Comparison SLE4442 cards, each card compared to the card password, if all the card data become to read-only, you will not be able to do any write operation. Secure storage area (except the error counter outside) will not be able to read and write.

  Parameters:
    `passwd` - The data buffer pointer password, password here to store data migration and card in the password.
  Returns:
    0 if successful, -1 if failed.

### sle4442_changePassword

    public int sle4442_changePassword(byte[] passwd)

  Change password.

  Parameters:
    `passwd` - The data buffer point to the new password.
  Returns:
    0 if successful, -1 if failed.

### sle4442_readErrorCounter

    public int sle4442_readErrorCounter(byte[] errorCount)

  Read error code value.

  Parameters:
    `errorCount` - The data buffer point to error count, 1Byte.
  Returns:
    0 if successful, -1 if failed.

### sle4436_reset

    public int sle4436_reset(byte[] pAtr)

  Reset the SLE4436.

  Parameters:
    `pAtr` - To store the return ATR.
  Returns:
    Length of ATR, negative number if failed.

### sle4436_readMemory

    public byte[] sle4436_readMemory(int addr,
                                     int length)

  Read the data stored in main memory for SLE4436.

  Parameters:
    `addr` - The starting address of operation data, the range of the parameters of the SLE4436 card is 0 to 112.
    `length` - To read the data length, the range of the parameters of the SLE4436 card is 1 to 112. ByteAddr and Length cannot be greater than the actual capacity of the card, otherwise the reader will refuse to execute the command and returns an error.
  Returns:
    Byte array indicating the store data if successful, null if failed.

### sle4436_writeMemory

    public int sle4436_writeMemory(int addr,
                                   byte[] data,
                                   int dataLen)

  Write data to the main storage area SLE4436.

  Parameters:
    `addr` - The starting address of operation data, the range of the parameters of the SLE4436 card is 0 to 112.
    `data` - The data to be written.
    `dataLen` - The data length.
  Returns:
    0 if successful, -1 if failed.

### sle4436_verifyPassword

    public int sle4436_verifyPassword(byte[] passwd)

  Submit the transfer data, enter the personalization mode.

  Parameters:
    `passwd` - The data buffer pointer password, password here to store data migration and card in the password.
  Returns:
    0 if successful, -1 if failed.

### sle4436_regIncrease

    public int sle4436_regIncrease(int shiftBits)

  Move the register.

  Parameters:
    `shiftBits` - Move Bits.
  Returns:
    0 if successful, -1 if failed.

### sle4436_readBit

    public int sle4436_readBit(byte[] pData)

  Read values from the Card bit.

  Parameters:
    `pData` - Store the value read from the card.
  Returns:
    0 if successful, -1 if failed.

### sle4436_writeBit

    public int sle4436_writeBit()

  Write a bit for Card.

  Parameters:
    none
  Returns:
    0 if successful, -1 if failed.

### sle4436_reloadByte

    public int sle4436_reloadByte()

  Reload Byte.

  Parameters:
    none
  Returns:
    0 if successful, -1 if failed.

### sle4436_decValue

    public int sle4436_decValue(int pValue)

  Reduction balance.

  Parameters:
    `pValue` - The amount of money to be eduction.
  Returns:
    The card balance if successful, -1 if failed.

### sle4428_reset

    public int sle4428_reset(byte[] pAtr)

  reset the SLE4428.

  Parameters:
    `pAtr` - To store the return ATR.
  Returns:
    Length of ATR, negative number if failed.

### sle4428_readMemory

    public byte[] sle4428_readMemory(int addr,
                                     int length)

  Read the data stored in main memory for SLE4428.

  Parameters:
    `addr` - The starting address of operation data, the range of the parameters of the SLE4428 card is 0 to 0x3FF. `
    `length` - To read the data length, the range of the parameters of the SLE4428 card is 1 to 0x400. ByteAddr and Length cannot be greater than the actual capacity of the card, otherwise the reader will refuse to execute the command and returns an error.
  Returns:
    Byte array indicating the store data if successful, null if failed.

### sle4428_writeMemory

    public int sle4428_writeMemory(int addr,
                                   byte[] data,
                                   int dataLen)

  Write data to the main storage area SLE4428.

  Parameters:
    `addr` - The starting address of operation data, the range of the parameters of the SLE4428 card is 0 to 0x3FF.
    `data` - The data to be written.
    `dataLen` - The data length, max 0x400.
  Returns:
    0 if successful, -1 if failed.

### sle4428_password

    public int sle4428_password(int mode,
                                byte[] data)

  Submit the transfer data, enter the personalization mode.

  Parameters:
    `mode` - 0 verify password or 1 changed password.
    `data` - The data buffer pointer password, password here to store data migration and card in the password.
  Returns:
    0 if successful, -1 if failed.

### at88sc102_read

    public byte[] at88sc102_read(int addr,
                                 int length)

  Read the data stored in main memory for At88sc102.

  Parameters:
    `addr` - The starting address of operation data, the range of the parameters of the At88sc102 card is 0 to 0xFF.
    `length` - To read the data length, the range of the parameters of the At88sc102 card is 1 to 0x100. ByteAddr and Length cannot be greater than the actual capacity of the card, otherwise the reader will refuse to execute the command and returns an error.
  Returns:
    Byte array indicating the store data if successful, null if failed.

### at88sc102_write

    public int at88sc102_write(int addr,
                               byte[] data,
                               int dataLen)

  Write data to the main storage area At88sc102.

  Parameters:
    `addr` - The starting address of operation data, the range of the parameters of the At88sc102 card is 0 to 0xFF.
    `data` - The data to be written.
    `dataLen` - The data length, 0x100.
  Returns:
    0 if successful, -1 if failed.

### at88sc102_VerifyPassword

    public int at88sc102_VerifyPassword(int type,
                                        byte[] data,
                                        int length)

  Check & Verify password for At88sc102.

  Parameters:
    `type` - type of password. Value:
    0: SC
    1: erase EZ1 password
    2: erase EZ2 password
    `data` - Password to verify. If type is SC, the len should be 2Bytes. EZ1, the len should be 6Bytes. EZ2, the len should be 4Bytes.
    `length` - The data length.
  Returns:
    0 if successful, -1 if failed.