my card is gemalto v2.2.1,T=0 and It doesn't support apdu chain. I saw samples that they are using ExtendedLength but my card not supported. I wrote a code but I have problem with it. Can every body tell me Where do I make mistake or please give me a solution.
public class ap2 extends Applet {
private Object[] FileArray;
private ap2() {
// I want to save three binary data
FileArray=new Object[3];
}
public static void install(byte bArray[], short bOffset, byte bLength)
throws ISOException {
new ap2().register();
}
public void process(APDU arg0) throws ISOException {
// TODO Auto-generated method stub
}
private void ReadBinaryData(APDU apdu)
{
short offset = getoffset_read(apdu);
byte[] buf= apdu.getBuffer();
//I send file index in p1 from host and get File Index in card
byte p1value=buf[ISO7816.OFFSET_P1];
byte[] FileObj=(byte[]) FileArray[p1value];
short le = apdu.setOutgoing();
if(le == 0 || le == 256) {
le = (short)(FileObj.length - offset);
if(le > 256) le = 256;
}
boolean eof = false;
if((short)(FileObj.length - offset) < le) {
le = (short)(FileObj.length - offset);
eof = true;
}
apdu.setOutgoingLength(le);
apdu.sendBytesLong(FileObj, offset, le);
if(eof) {
ISOException.throwIt(SW_END_OF_FILE);
}
}
private short getoffset_read(APDU apdu)
{
?????????????????
}
private void WriteBinaryData(APDU apdu)
{
if(FileCount==3)
{
ISOException.throwIt(SW_END_OF_ThreeFILES);
}
byte[] buf = apdu.getBuffer();
short offset = getoffset_write();
byte lc=buf[ISO7816.OFFSET_LC];
if((short)(offset + lc) >((byte[])FileArray[FileCount]).length) {
ISOException.throwIt(SW_WRONG_LENGTH);
}
apdu.setIncomingAndReceive();
Util.arrayCopyNonAtomic(buf, ISO7816.OFFSET_CDATA,(byte[]) FileArray[FileCount],offset,lc);
}
private short getoffset_write()
{
????????????????????
}
I don't know how to calculate offset.