Page 1 of 1
Specify the right interface for my code
Posted: Thu Mar 09, 2017 4:08 am
by Classicni
I have finished an applet but there is a special point. Part of my code should run only under contact interface, and some of them should run only under contactless interface. So now my question is how to specify the right interface for my code. Is there any method to specify the interface firstly before running the code. I appreciate any help.
Re: Specify the right interface for my code
Posted: Fri Mar 10, 2017 1:19 am
by Crawford
Maybe this code helps:
Code: Select all
byte protocolMedia = (byte) (apdu.getProtocol() & APDU.PROTOCOL_MEDIA_MASK);
if ((protocolMedia == APDU.PROTOCOL_MEDIA_CONTACTLESS_TYPE_A) || (protocolMedia == APDU.PROTOCOL_MEDIA_CONTACTLESS_TYPE_B)) {
// Contactless interface;
switch (buf[ISO7816.OFFSET_INS]) {
case INS_READ_RECORD:
contactless_readRecord(apdu, buf);
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
} else {
// Contact interface;
switch (buf[ISO7816.OFFSET_INS]) {
case INS_READ_RECORD:
contact_readRecord(apdu, buf);
break;
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
}
Re: Specify the right interface for my code
Posted: Sun Mar 12, 2017 10:35 pm
by Classicni
Thanks for your help. It indeed helps.