FileDocCategorySizeDatePackage
CardDevice.javaAPI DocphoneME MR2 API (J2ME)7700Wed May 02 18:00:38 BST 2007com.sun.cardreader

CardDevice

public abstract class CardDevice extends Object
This class represents card device abstraction.

Fields Summary
private int
startSlotNumber
Number of start slot of the device. The slot factory holds a table with global slot numbers. Every device operates with local ones (numbers inside the device). startSlotNumber is global number of first local slot.
private static final int
DEFAULT_SAT_SLOT
Default SAT slot number.
private byte[]
ATR
Answer-To-Reset bytes receiving during last reset.
Constructors Summary
Methods Summary
public booleancheckSlotNumber(int slot)
Checks if the global slot number belongs to the device.

param
slot Global slot number
return
True if slot belongs to this device, otherwise false

        return ((slot >= this.startSlotNumber) && 
                (slot < this.startSlotNumber + getSlotCount()));
    
public abstract voidclose()
Closes the device. No exceptions thrown to avoid mess in exception handlers trying to clean up and close the device.

public voidcloseSlot(int slot)
Close the specified slot. This is for situations when slot closure requires additional actions. By default doing nothing but this is not an abstract method becuase most devices don't need it.

param
slot Slot number
throws
IOException If slot close failed.

    
public voidcmdPowerDown()
Performs 'POWER DOWN' command. By default does nothing.

throws
IOException If command failed.

    
protected abstract intcmdReset(byte[] atr)
Performs reset of device. Returns ATR into provided buffer

param
atr Buffer for ATR bytes
return
Length of ATR
throws
IOException If a reset failed.

protected abstract intcmdXfer(byte[] request, byte[] response)
Performs data transfer to the device.

param
request Request bytes
param
response Response bytes
return
Length of response
throws
IOException If a data transfer failed.

public byte[]getATR()
Gets Answer-To-Reset bytes from the device.

return
ATR bytes
throws
IOException If data transfer failed.

        return ATR;
    
public intgetSlotCount()
Gets number of slots on a device. Default implementation returns 1 which is ok for most devices.

return
Number of slots on a device

 
        return 1; 
    
public intgetStartSlotNumber()
Gets start slot number in the global slot numbering scheme.

return
Number of the first device slot in the global numbering scheme

        return this.startSlotNumber; 
    
public abstract voidinit()
Initializes the device.

throws
IOException If a device initialization failed.
throws
CardDeviceException If a device configuration is bad.

public abstract booleanisCardChanged()
Checks if the card in the selected slot was changed since last call or since last reset. Called after any transfer operation, so implementation can check and store that status during this operation.

return
true if was changed, false otherwise.
throws
IOException If something fails.

public booleanisSatSlot(int slotNumber)
Checks if this slot is SAT slot. Default implementation returns true if slotNumber is 0.

param
slotNumber Slot number
return
true if the slot is dedicated for SAT, false otherwise
throws
IOException If an error occured.

 
        return slotNumber == DEFAULT_SAT_SLOT; 
    
public abstract voidlock()
Performs platform lock of the device. This is intended to make sure that no other native application uses the same device during a transaction.

throws
IOException If a device locking failed.

public voidopenSlot(int slot, SecurityToken token)
Open the specified slot. This is for situations when slot creation requires additional actions. By default doing nothing but this is not an abstract method because most devices don't need it.

param
slot Slot number
param
token Security token for this slot
throws
IOException If slot opening failed.

    
                            
          
    
                             
       
    
                                        
         
    
                   
         

                                                         
            
    
public voidreset()
Resets the device. Wrapper method for cmdReset.

throws
IOException If a reset failed.

        int bytes_read;
        byte[] r = new byte[255];
        
        bytes_read = cmdReset(r);
        if (bytes_read > 0) {
            ATR = new byte[bytes_read];
            System.arraycopy(r, 0, ATR, 0, bytes_read);
        } else
            throw new IOException("Empty ATR");
    
public abstract voidselectSlot(int slot)
Selects the current slot for the subsequent transfer operations. For the one-slot devices the default slot number is 0.

param
slot Slot number
throws
IOException If a slot selection failed.

public voidsetStartSlotNumber(int slot)
Stores start slot number.

param
slot Number of the first device slot in the global numbering scheme

        this.startSlotNumber = slot;
    
public abstract voidunlock()
Unlocks the device.

throws
IOException If a device unlocking failed.

public intxfer(byte[] request, byte[] response)
Performs data transfer to the device. Wrapper method for cmdXfer.

param
request Request bytes
param
response Response bytes
return
Length of response
throws
IOException If a data transfer failed.

        return cmdXfer(request, response);