android.device
Class PiccManager

java.lang.Object
  extended by android.device.PiccManager

public class PiccManager
extends java.lang.Object

The PiccManager class is used to initialize and control RF Card reader.

To read RF Card with this class, use the following steps:

  1. Obtain an instance of RF Card reader with PiccManager picc = new PiccManager().
  2. Call open() to initialize the RF card reader.
  3. Start searching the RF card with request(byte[], byte[] ).
  4. anti-collision and select card with antisel(byte[], byte[] ).
  5. Attach the target before transmitting apdu command with #dactivate().
  6. Transmit APDU command and get the response with apduTransmit(byte[] , int , byte[] , byte[] ).
  7. Detach the target. If you want to send APDU again, you should attach it.with #deactivate().
  8. Close the RF card reader. with close().

    For more information about the RF card reader, read the samples folder below PiccManager Demo.


Constructor Summary
PiccManager()
           
 
Method Summary
 int activate()
          activate card to start sending APDU。
 int activateEx(byte[] art)
          activate card to start sending APDU。
 int antisel(byte[] sn, byte[] sak)
          anti-collision and select card and returns the serial number of the card
 int apduTransmit(byte[] sent, int sentlen, byte[] rsp)
          Transmit APDU exchange commands:e.g.
 int apduTransmit(byte[] cmd, int cmdlen, byte[] rsp, byte[] sw)
          Transmit APDU commands
 int apduTransmit(byte[] cmd, int cmdlen, byte[] rsp, int crc, int speed)
          Transmit APDU exchange commands:e.g.
 int apduTransmit(int cmd, int num, byte[] sent, int sentlen, byte[] rsp)
          Transmit APDU commands for F Card
 int close()
          Close the RF card reader
 int deactivate(byte mode)
          Deavtivate a card
 int enableRATS(byte value)
          enable RATS,
 int idcard_apduTransmit(byte[] sent, int sentlen, byte[] rsp)
          Transmit APDU commands
 int idcard_init()
          init the IDCARD
 int m1_amount(int blkNo)
          read the amount for the block number
 int m1_decrement(int blkNO, int iMoney)
          decrement the value block by iMoney amount
 int m1_increment(int blkNo, int iMoney)
          increment the value block by iMoney amount
 int m1_init(int blkNo, int value)
          init the value block by value
 int m1_keyAuth(int keyType, int blnNo, int keylen, byte[] keyBuf, int iSeriNumlen, byte[] seriNum)
          authenticate a key
 int m1_readBlock(int blkNo, byte[] pReadBuf)
          To read a block
 int m1_restore(int blkNo)
          Move the content of a block into temporary data register
 int m1_transfer(int blkNo)
          transfer from temporary internal data register to value block
 int m1_writeBlock(int blkNo, int iLenWriteBuf, byte[] pWriteBuf)
          Write a block into the card
 int open()
          Open the RF card reader
 int request_norats(byte[] mode, byte[] atq)
          Request card and no enable RATS
 int request_type(byte pollType, byte[] mode, byte[] atq)
          Request Specify card type
 int request(byte[] mode, byte[] atq)
          Request card
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PiccManager

public PiccManager()
Method Detail

open

public int open()
Open the RF card reader

Returns:
0 if successful, and negative number if failed

enableRATS

public int enableRATS(byte value)
enable RATS,

Returns:
0 if successful, and negative number if failed

request

public int request(byte[] mode,
                   byte[] atq)
Request card

Parameters:
mode - returns the card type, could be 'A' or 'B'
atq - returns the ATQ
Returns:
length of ATQ

request_norats

public int request_norats(byte[] mode,
                          byte[] atq)
Request card and no enable RATS

Parameters:
mode - returns the card type, could be 'A' or 'B'
atq - returns the ATQ
Returns:
length of ATQ

request_type

public int request_type(byte pollType,
                        byte[] mode,
                        byte[] atq)
Request Specify card type

Parameters:
pollType - (bit0 A card,bit1 B card ,bit2 Felica-212 card,bit3 Felica-424 card ,bit4 15693 card,bit5 18000 card)
mode - returns the card type, A’ : A card,’B’ : B card
atq - returns the ATQ
Returns:
length of ATQ

antisel

public int antisel(byte[] sn,
                   byte[] sak)
anti-collision and select card and returns the serial number of the card

Parameters:
sn - serial number
sak - SAK
Returns:
length of sn,negative number if failed

activate

public int activate()
activate card to start sending APDU。(skip this call for M1 card).

Returns:
0 if successful, negative number if failed

activateEx

public int activateEx(byte[] art)
activate card to start sending APDU。(skip this call for M1 card).

Parameters:
[out] - art buff
Returns:
0 if successful, negative number if failed

apduTransmit

public int apduTransmit(byte[] cmd,
                        int cmdlen,
                        byte[] rsp,
                        byte[] sw)
Transmit APDU commands

Parameters:
cmd - APDU command to be sent, the command format with ISO7816 Transmission protocol
cmdlen - APDU length
rsp - Response from card
sw - status bytes
Returns:
The APDU length. Negative number if failed

apduTransmit

public int apduTransmit(byte[] sent,
                        int sentlen,
                        byte[] rsp)
Transmit APDU exchange commands:e.g. Desfire Card

Parameters:
cmd - APDU command to be sent
cmdlen - APDU length
rsp - Response from card
Returns:
The APDU length. Negative number if failed

apduTransmit

public int apduTransmit(byte[] cmd,
                        int cmdlen,
                        byte[] rsp,
                        int crc,
                        int speed)
Transmit APDU exchange commands:e.g. Desfire Card

Parameters:
cmd - APDU command to be sent
cmdlen - APDU length
rsp - Response from card
crc - APDU CRC
rsp - APDU speed
Returns:
The APDU length. Negative number if failed

deactivate

public int deactivate(byte mode)
Deavtivate a card

Parameters:
mode - 0x00 imply HALT, deactivate card and return without checking for card removal. 0x01 imply REMOVE, deactivate card and check for card removal; 0x02 imply EMV compliant card removal, and check for card removal.
Returns:
0 if successful, negative number if failed

close

public int close()
Close the RF card reader

Returns:
0 if successful, negative number if failed

m1_keyAuth

public int m1_keyAuth(int keyType,
                      int blnNo,
                      int keylen,
                      byte[] keyBuf,
                      int iSeriNumlen,
                      byte[] seriNum)
authenticate a key

Parameters:
keyType - key type: 0 means A key, 1 means B key
blnNo - block number
keylen - key length
keyBuf - the key
iSeriNumlen - serial number length
seriNum - serial number
Returns:
0 if successful, negative number if failed

m1_readBlock

public int m1_readBlock(int blkNo,
                        byte[] pReadBuf)
To read a block

Parameters:
blkNo - block number
pReadBuf - to store the read data
Returns:
0 if successful, negative number if failed

m1_writeBlock

public int m1_writeBlock(int blkNo,
                         int iLenWriteBuf,
                         byte[] pWriteBuf)
Write a block into the card

Parameters:
blkNo - the block number
iLenWriteBuf - length of buffer to be written
pWriteBuf - the buffer to be written
Returns:
0 if successful, negative number if failed

m1_increment

public int m1_increment(int blkNo,
                        int iMoney)
increment the value block by iMoney amount

Parameters:
blkNo - the value block number
iMoney - the amount to be decremented
Returns:
0 if successful, negative number if failed

m1_decrement

public int m1_decrement(int blkNO,
                        int iMoney)
decrement the value block by iMoney amount

Parameters:
blkNO - the value block number
iMoney - the amount to be decremented
Returns:
0 if successful, negative number if failed

m1_restore

public int m1_restore(int blkNo)
Move the content of a block into temporary data register

Parameters:
blkNo - the block number to be operated on
Returns:
0 if successful, negative number if failed

m1_transfer

public int m1_transfer(int blkNo)
transfer from temporary internal data register to value block

Parameters:
blkNo - the block number to be operated on
Returns:
0 if successful, negative number if failed

m1_init

public int m1_init(int blkNo,
                   int value)
init the value block by value

Parameters:
blkNo - the value block number
value - the amount to be init
Returns:
0 if successful, negative number if failed

m1_amount

public int m1_amount(int blkNo)
read the amount for the block number

Parameters:
blkNo - the value block number
Returns:
The amount. Negative number if failed

idcard_init

public int idcard_init()
init the IDCARD

Returns:
0 if successful, negative number if failed

idcard_apduTransmit

public int idcard_apduTransmit(byte[] sent,
                               int sentlen,
                               byte[] rsp)
Transmit APDU commands

Parameters:
cmd - APDU command to be sent
cmdlen - APDU length
rsp - Response from IDCard
Returns:
The response data length. Negative number if failed

apduTransmit

public int apduTransmit(int cmd,
                        int num,
                        byte[] sent,
                        int sentlen,
                        byte[] rsp)
Transmit APDU commands for F Card

Parameters:
cmd - APDU command to be sent
cmdlen - APDU length
rsp - Response from F Card
Returns:
The response data length. Negative number if failed