AclFileSystempublic class AclFileSystem extends FileSystemAbstract This class provides interface to card file system. |
Fields Summary |
---|
private static final int | CARD_BUFFERConstant defines size of the card buffer | private static final int | P1_P2Constant defines parameters P1, P2 in the apdu command | private byte[] | ATRInternal buffer for ATR | private int | unitSizevariable defines the unit size in the INS_READ command | public DIRF | DIRDIR file object |
Constructors Summary |
---|
public AclFileSystem(Connection apdu)Constructs new AclFileSystem object.
super(apdu);
ATR = apdu.getATR();
/* Get FCI from previous operation */
byte[] prevFCI = apdu.getFCI();
/*
* It is assumed that in case of work with application the FCI
* contains successfull result of the selectApplication operation,
* i.e. 0x9000. In case of work with the card file system the FCI
* array will contain actual FCI of the master file and length of the
* array will be > 2
*/
if (prevFCI.length > 2) {
parseATR();
apdu.setUnitSize(unitSize);
try {
DIR = new DIRF(this);
DIR.load();
} catch (TLVException te) {
throw new IOException("Wrong file TLV structure");
}
catch (IOException ie) {
throw new IOException("Wrong DIR file");
}
} else {
apdu.setUnitSize(unitSize);
}
apdu.setCLAbyte((byte)0);
|
Methods Summary |
---|
private void | parseATR()Parses the ATR.
At the moment defines a unit size only
for (int i = ATR.length - 1; i > 0; i--) {
if (((ATR[i] & 0xF0) == 0x70) &&
((ATR[i] & 0x0F) >= 2)) {
unitSize = (1 << (ATR[i+2] & 0x07)) / 2;
break;
}
}
| public byte[] | readData(int offset, int length, int fileOffset)Reads part of selected file.
Vector v = new Vector();
int len = CARD_BUFFER;
int readLength = 0;
while (true) {
byte[] result = apdu.resetCommand().
sendCommand(INS_READ, fileOffset/unitSize, len, false);
int lastSW = ((result[result.length - 2] & 0xff) << 8) |
(result[result.length - 1] & 0xff);
if (lastSW != 0x9000) {
break;
}
v.addElement(result);
offset += len;
fileOffset += len;
readLength += result.length - 2;
if (result.length - 2 < len) {
break;
}
}
byte[] data = new byte[readLength];
offset = 0;
for (int i = 0; i < v.size(); i++) {
byte[] r = (byte[])v.elementAt(i);
System.arraycopy(r, 0, data, offset, r.length - 2);
offset += r.length - 2;
}
currentFileSize = readLength;
return data;
| public byte[] | readFile()Reads the current EF.
byte[] data = readData(0, currentFileSize, 0);
return data;
| public void | select(short id)Selects file by ID.
byte[] data = apdu.resetCommand().
putShort(id).
sendCommand(INS_SELECT, P1_P2);
isEFSelected = false;
currentFileSize = 0;
if (data.length == 2) {
return; // FCI is empty
}
/* parse FCI */
if (Utils.getU2(data, data.length - 2) != 0x9000) {
throw new IOException("Bad FCI");
}
isEFSelected = true;
|
|