This is an old topic which has already been answered but I would like to update at the current moment in time of this posting, I am not sure if the optional data can be sent together with SW (non-0x9000) anymore with exception of 0x6D00. I have tested on an Infineon (Feitian A22CR), Infineon SECORA ID and an NXP JCOP4 P71 for both JC 2.2.2 and JC 3.0.4. JavaCards.
I have created a simple applet code requiring only a single Java class file that will return 'hello' together with the SW (enter the SW inside the Command APDU's data as shown in screenshot below) and it will attempt to return both the text 'hello' and the SW.
Seems like only 0x9000 and 0x6D00 seems to return the 'hello' text.
Has anyone that have gotten 0x6200 and 0x6300 to work with sending data as well, please post a sample code as I think it will benefit many of us here.
Applet code:
package TestAPDU;
import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.JCSystem;
import javacard.framework.Util;
public class TestAPDU extends Applet {
public byte[] swStore = JCSystem.makeTransientByteArray((short) 2, JCSystem.CLEAR_ON_DESELECT);
public static void install(byte[] bArray, short bOffset, byte bLength) {
new TestAPDU().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
}
public void process(APDU apdu) {
if (selectingApplet()) {
return;
}
byte[] buf = apdu.getBuffer();
switch (buf[ISO7816.OFFSET_INS]) {
case (byte) 0x00:
apdu.setIncomingAndReceive();
swStore[0] = buf[5];
swStore[1] = buf[6];
buf[0] = (byte) 0x68;
buf[1] = (byte) 0x65;
buf[2] = (byte) 0x6C;
buf[3] = (byte) 0x6C;
buf[4] = (byte) 0x6F;
apdu.setOutgoing();
apdu.setOutgoingLength((short) 5);
apdu.sendBytes((short) 0, (short) 5);
ISOException.throwIt(Util.makeShort(swStore[0], swStore[1]));
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
}