com.datecs.api.universalreader
Class UniversalReader.MifareReader

java.lang.Object
  extended by com.datecs.api.universalreader.UniversalReader.MifareReader
Enclosing class:
UniversalReader

public final class UniversalReader.MifareReader
extends java.lang.Object

This class provides functionality for the Mifare reader.


Method Summary
 int anticollision()
          Returns the serial number of one of requested Mifare cards.
 void authenticate(int sn, int block, int type, byte[] key)
          Authenticates Mifare card for operation.
 void authenticate(int sn, int block, int type, int selector)
          Authenticates Mifare card for operation with key stored into Mifare reader EEPROM memory.
 void config()
          Configures Mifare card reader.
 void decrement(int src, int dst, int value)
          Performs value decrement operation in Mifare card.
 int getSerialNumber()
          Gets the serial number of Mifare reader.
 void halt()
          Puts the selected Mifare card into 'idle' state.
 void increment(int src, int dst, int value)
          Performs value increment operation in Mifare card.
 void loadKey(int selector, byte[] key)
          Stores key into Mifare reader EEPROM.
 byte[] read(int block)
          Reads block from Mifare card.
 byte[] readEeprom(int address, int length)
          Reads data from Mifare reader EEPROM memory.
 int request(boolean all)
          Requests for Mifare cards.
 void restore(int src, int dst, int value)
          Performs value restore operation in Mifare card.
 int select(int sn)
          Selects a Mifare card.
 void setPower(boolean on)
          Powers on/off Mifare card reader.
 void write(int block, byte[] data)
          Writes block to Mifare card.
 void write(int block, int data)
          Writes data to Mifare card.
 void writeEeprom(int address, byte[] data)
          Writes data to Mifare reader EEPROM memory.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setPower

public void setPower(boolean on)
              throws java.io.IOException,
                     UniversalReaderException
Powers on/off Mifare card reader.

Parameters:
on - the flag indicates where to power on/off the reader.
Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

config

public void config()
            throws java.io.IOException,
                   UniversalReaderException
Configures Mifare card reader.

This command must be execute right after power on the reader.

Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

request

public int request(boolean all)
            throws java.io.IOException,
                   UniversalReaderException
Requests for Mifare cards.

Parameters:
all - the flag indicates where the request processes over all cards in range or only over idle state cards.
Returns:
the ATQA (Answer To Request A) value. Consult Mifare card documentation.
Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

anticollision

public int anticollision()
                  throws java.io.IOException,
                         UniversalReaderException
Returns the serial number of one of requested Mifare cards.

Returns:
the serial number of Mifare card.
Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

select

public int select(int sn)
           throws java.io.IOException,
                  UniversalReaderException
Selects a Mifare card.

Parameters:
sn - the serial number of Mifare card.
Returns:
the SAK (Select Acknowledge) value. For more information consults with Mifare card documentation.
Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

authenticate

public void authenticate(int sn,
                         int block,
                         int type,
                         byte[] key)
                  throws java.io.IOException,
                         UniversalReaderException
Authenticates Mifare card for operation.

If key is null, a NullPointerException is thrown.

If key.length != 6, a IllegalArgumentException is thrown.

Parameters:
sn - the serial number of Mifare card.
block - the block number of Mifare card requested for authentication.
type - the key type of authentication, where 0x60 is type A and 0x61 is type B.
key - the byte array contains 6 bytes authentication key.
Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

read

public byte[] read(int block)
            throws java.io.IOException,
                   UniversalReaderException
Reads block from Mifare card.

Parameters:
block - the block number.
Returns:
the data read form from Mifare card.
Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

write

public void write(int block,
                  byte[] data)
           throws java.io.IOException,
                  UniversalReaderException
Writes block to Mifare card.

If data is null, a NullPointerException is thrown.

If data.length != 16, a IllegalArgumentException is thrown.

Parameters:
block - the block number.
data - the byte array contains 16 bytes data to write.
Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

increment

public void increment(int src,
                      int dst,
                      int value)
               throws java.io.IOException,
                      UniversalReaderException
Performs value increment operation in Mifare card.

Parameters:
src - the source block number.
dst - the destination block number.
value - the value to increments with.
Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

decrement

public void decrement(int src,
                      int dst,
                      int value)
               throws java.io.IOException,
                      UniversalReaderException
Performs value decrement operation in Mifare card.

Parameters:
src - the source block number.
dst - the destination block number.
value - the value to decrement with.
Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

restore

public void restore(int src,
                    int dst,
                    int value)
             throws java.io.IOException,
                    UniversalReaderException
Performs value restore operation in Mifare card.

Parameters:
src - the source block number.
dst - the destination block number.
value - the value to restore with.
Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

halt

public void halt()
          throws java.io.IOException,
                 UniversalReaderException
Puts the selected Mifare card into 'idle' state.

Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

getSerialNumber

public int getSerialNumber()
                    throws java.io.IOException,
                           UniversalReaderException
Gets the serial number of Mifare reader.

Returns:
the serial number of Mifare reader.
Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

writeEeprom

public void writeEeprom(int address,
                        byte[] data)
                 throws java.io.IOException,
                        UniversalReaderException
Writes data to Mifare reader EEPROM memory.

If data is null, a NullPointerException is thrown.

If data.length < 1 || data.length > 255, a IllegalAccessException is thrown.

Parameters:
address - the address in EEPROM memory.
data - the data.
Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

write

public void write(int block,
                  int data)
           throws java.io.IOException,
                  UniversalReaderException
Writes data to Mifare card.

Parameters:
block - the block number.
data - the data.
Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

loadKey

public void loadKey(int selector,
                    byte[] key)
             throws java.io.IOException,
                    UniversalReaderException
Stores key into Mifare reader EEPROM.

If key is null, a NullPointerException is thrown.

If key.length != 6, a IllegalArgumentException is thrown.

Parameters:
selector - the key selector number.
key - the byte array contains 6 bytes authentication key.
Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

authenticate

public void authenticate(int sn,
                         int block,
                         int type,
                         int selector)
                  throws java.io.IOException,
                         UniversalReaderException
Authenticates Mifare card for operation with key stored into Mifare reader EEPROM memory.

Parameters:
sn - the serial number of Mifare card.
block - the block number of Mifare card requested for authentication.
type - the key type of authentication, where 0x60 is type A and 0x61 is type B.
selector - the number of key selector.
Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.

readEeprom

public byte[] readEeprom(int address,
                         int length)
                  throws java.io.IOException,
                         UniversalReaderException
Reads data from Mifare reader EEPROM memory.

Parameters:
address - the EEPROM memory address.
length - the length of data requested for reading.
Returns:
the requested EEPROM memory data.
Throws:
java.io.IOException - if an I/O error occurs.
UniversalReaderException - if an error occurs during execution.