FileDocCategorySizeDatePackage
Connection.javaAPI DocphoneME MR2 API (J2ME)5731Wed May 02 18:00:38 BST 2007com.sun.satsa.util

Connection

public class Connection extends Object
Represents APDU connection to the WIM application.

Fields Summary
public int
lastSW
The last response APDU status word.
private byte[]
command
Temporary buffer for APDU command.
private int
offset
Current offset in the command buffer.
private com.sun.midp.io.j2me.apdu.Handle
h
APDU connection handle.
private int
unitSize
Unit size for the read command
private byte
CLAbyte
CLAbyte for the send command
Constructors Summary
public Connection(com.sun.midp.io.j2me.apdu.Handle h)
Constructs new connection object.

param
h APDU connection handle.

        this.h = h;
        command = new byte[255];
    
Methods Summary
public voiddone()
Safely closes the connection.

        try {
            if (h != null) {
                APDUManager.closeConnection(h);
            }
        } catch (IOException e) {} // ignore
        h = null;
    
public byte[]getATR()
This method returns the ATR received from the card that this Handle object is used to communicate with.

return
ATR information received from the card at startup or reset. In case of I/O troubles returns null.

        return h.getATR();
    
public byte[]getFCI()
This method returns the FCI received from the card that this Handle object is used to communicate with.

return
FCI information received from the card at startup or reset. In case of I/O troubles returns null.

        return h.getFCI();
    
public com.sun.satsa.util.ConnectionputByte(int data)
Places one byte into command buffer.

param
data byte to be placed
return
this connection object

        command[offset++] = (byte) data;
        return this;
    
public com.sun.satsa.util.ConnectionputBytes(byte[] data, int off, int length)
Places the byte sequence into the buffer.

param
data data to be placed
param
off data offset
param
length data length
return
this connection object

        System.arraycopy(data, off, command, offset, length);
        offset += length;
        return this;
    
public com.sun.satsa.util.ConnectionputShort(int data)
Places short value into the buffer.

param
data value to be placed
return
this connection object

        command[offset++] = (byte) (data >> 8);
        command[offset++] = (byte) data;
        return this;
    
public com.sun.satsa.util.ConnectionresetCommand()
Resets command buffer.

return
this connection object

        offset = 5;
        return this;
    
public byte[]sendCommand(int INS, int P1P2)
Sends the command.

param
INS INS byte for this command.
param
P1P2 APDU parameters value
return
response APDU
throws
IOException if IO error occurs

        return sendCommand(INS, P1P2, 240, true);
    
public byte[]sendCommand(int INS, int P1P2, int LE, boolean check)
Sends the command.

param
INS INS byte for this command.
param
P1P2 P1 and P2 values for this command
param
LE response expected length
param
check if true, verify that SW is 0x9000
return
response APDU
throws
IOException if IO error occurs


        command[0] = (byte) (CLAbyte | h.channel);
        command[1] = (byte) INS;
        command[2] = (byte) (P1P2 >> 8);
        command[3] = (byte) P1P2;
        command[4] = (byte) (offset - 5);
        putByte(LE);

        byte[] tmp = APDUManager.exchangeAPDU(h, command);

        lastSW = ((tmp[tmp.length - 2] & 0xff) << 8) |
                  (tmp[tmp.length - 1] & 0xff);

        if (check && lastSW != 0x9000) {
            throw new IOException("SW = " + Integer.toHexString(lastSW));
        }
        return tmp;
    
public voidsetCLAbyte(byte cla)
This method sets value for the CLAbyte variable

param
cla byte Required value.

        this.CLAbyte = cla;
    
public voidsetUnitSize(int unitSize)
This method sets value for the unitSize variable

param
unitSize int Required value.

        this.unitSize = unitSize;