I am writing an applet that stores 3 files of different sizes 5 Kb, 7 Kb and 11 Kb. I have got no problems with storing the files inside the applet. But when I try to read them back, I can only read the first two (smaller files). The third file throws an exception:
javax.smartcardio.CardException: Could not obtain response at sun.security.smartcardio.ChannelImpl.doTransmit(Unknown Source) at sun.security.smartcardio.ChannelImpl.transmit(Unknown Source) I have tried to figure out the problem and I have found out it has to do with the size of the file. So I created a test file of size 7 Kb and incremented this file bit by bit. It worked until I reached 7905 bytes. It means 7905 bytes is the maximum number of bytes I can read from the applet. I am chaining the response using sample code:
public void readFile(APDU apdu, short[] offset, short selectedFile, short MAX_APDU_SEN, byte OFFSET_SENT) { byte[] file = getFile(selectedFile); if (file == null) { + ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND);+ } // work out how many bytes to send this time and how many will be left short remain = (short) (file.length - offset[OFFSET_SENT]); boolean chain = remain > MAX_APDU_SEN; short sendLen = chain ? MAX_APDU_SEN : remain; apdu.setOutgoing(); apdu.setOutgoingLength(sendLen); apdu.sendBytesLong(file, offset[OFFSET_SENT], sendLen); // Check to see if there are more APDU's to send if (chain) { +offset[OFFSET_SENT] = sendLen; // count the bytes sent ISOException.throwIt(ISO7816.SW_BYTES_REMAINING_00); // indicate there are more bytes to come } else {+ offset[OFFSET_SENT] = 0; // no more bytes to send } } I have tried two different types of cards i.e JC 2.2.1 (36Kb) and JC 2.2.2 (80Kb) compatible cards but they all behave the same.
Any help please?