Fields Summary |
---|
private CardDevice | deviceDevice object. |
private int | slotNumberLocal slot number (inside the device). |
SecurityToken | securityTokenSecurity token for this slot. |
private boolean | openedIndicates that the slot has been opened. |
private int | cardSessionIdUnique card session identifier. |
private static int | sessionIdThis field is used to assign unique card session identifiers. |
private byte[] | ATRATR bytes kept since last reset. |
private boolean | cardChangedA flag which shows if the card was changed. |
private byte[] | isAliveAPDUisAlive command APDU. |
private byte[] | isAliveResponseisAlive command response buffer. |
Methods Summary |
---|
public void | closeSlot()Closes the slot in case of error.
device.closeSlot usually
does nothing.
Used for socket-like 'devices'.
if (opened) {
device.closeSlot(slotNumber);
}
opened = false;
|
private boolean | doIsAlive()Checks if the the connection is still live or not by trying to
send an APDU to close channel 0. If we get an IOException back
that means a card or cref is gone.
try {
lockSlot();
xferData(true, isAliveAPDU, isAliveResponse);
unlockSlot();
return true;
} catch (IOException e) {
return false;
}
|
public byte[] | getATR()Gets ATR bytes from the device.
byte[] result;
if (opened && ATR.length > 0) {
result = new byte[ATR.length];
System.arraycopy(ATR, 0, result, 0, ATR.length);
} else {
result = null;
}
return result;
|
public int | getCardSessionId()Returns the card session identifier.
This number is different for different card sessions.
return (opened && !cardChanged) ? cardSessionId : -1;
|
protected CardDevice | getDevice()Gets device of this slot. For using in derived classes.
return this.device;
|
public int | getSlotNumber()Gets local device slot number.
return slotNumber;
|
public void | initACL()Initializes ACL for the slot.
boolean changed;
try {
lockSlot();
changed = isCardChanged();
unlockSlot();
if (changed) {
com.sun.satsa.acl.AccessControlManager.init(slotNumber);
}
} catch (IOException e) {} // ignored
|
public boolean | initConnection()Makes sure that slot is ready for connection.
boolean prevCardChanged;
lockSlot();
prevCardChanged = isCardChanged();
unlockSlot();
cardChanged = false;
return prevCardChanged;
|
public boolean | isAlive()Checks if the the connection is still live or not. It
is a public wrapper for doIsAlive . Also
checks if a card was changed. Slot must not be locked.
boolean alive = doIsAlive();
if (!alive) {
try {
if (!alive) {
lockSlot();
boolean changed = isCardChanged();
unlockSlot();
if (changed) {
alive = doIsAlive();
}
}
} catch (IOException e) {
alive = false;
}
}
return alive;
|
private boolean | isCardChanged()Checks if the card was withdrawn or inserted.
The device must be locked.
try {
if (device.isCardChanged()) {
closeSlot();
}
open();
} catch (IOException e) {
unlockSlot();
throw e;
}
if (cardChanged) {
return true;
}
return false;
|
public boolean | isSAT()Checks if this slot is SAT slot.
return device.isSatSlot(slotNumber);
|
public void | lockSlot()Starts operations with the slot.
All the transfer operations (xferData )
should be performed when the device is locked.
If any problem occurs an unlock must be done.
try {
device.lock();
open();
device.selectSlot(slotNumber);
}
catch (IOException e) {
unlockSlot();
throw e;
}
|
private void | open()Tries to open slot if it closed. Performes the 'RESET' command.
The device must be locked.
boolean openedSuccessfuly = false;
if (!opened) {
try {
device.openSlot(slotNumber, securityToken);
openedSuccessfuly = true;
device.selectSlot(slotNumber);
device.reset();
cardSessionId = sessionId++;
} catch (IOException ie) {
if (openedSuccessfuly) {
try {
device.closeSlot(slotNumber);
} catch (IOException ign) {} // ignored
}
throw new IOException("Cannot open slot #" +
slotNumber + ": " + ie);
}
ATR = device.getATR();
cardChanged = true;
opened = true;
}
|
public void | unlockSlot()Ends operations with the slot.
IOException is ignored.
try {
device.unlock();
}
catch (IOException e) {}
|
public int | xferData(byte[] request, byte[] response)Performs data transfer to the device slot.
It must be called where slot is locked.
return xferData(false, request, response);
|
private int | xferData(boolean aliveChecking, byte[] request, byte[] response)Performs data transfer to the device slot.
It must be called where slot is locked.
int bytes_read;
if (isCardChanged() && !aliveChecking) {
unlockSlot();
throw new InterruptedIOException("Card changed");
}
try {
bytes_read = device.xfer(request, response);
}
catch (IOException e) {
if (isCardChanged() && !aliveChecking) {
unlockSlot();
throw new InterruptedIOException("Card changed: " + e);
}
unlockSlot();
throw e;
}
catch (RuntimeException e) { // We must unlock slot
unlockSlot();
throw e;
}
if (isCardChanged() && !aliveChecking) {
unlockSlot();
throw new InterruptedIOException("Card changed");
}
return bytes_read;
|