Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect interface of incoming command?

I have a dual interface Java card that contains my applet. I want to have two different APDU response for a single command from different interfaces.

For example I want to respond to 00 10 00 00 APDU command with "Contact" when the command is received from the contact interface and respond "ContactLess" when this command is received from the contactless interface.

So, is there any method in the Java Card APIs or Global Platform APIs to detect the incoming command's interface?

like image 283
Ebrahim Ghasemi Avatar asked Dec 21 '25 02:12

Ebrahim Ghasemi


1 Answers

There is a method called getProtocol() in the javacard.framework.APDU class:

public static byte getProtocol()

Returns the ISO 7816 transport protocol type, T=1 or T=0 in the low nibble and the transport media in the upper nibble in use.

The interface is encoded in the upper nibble of the returned byte:

final byte transportMedia = (byte) (APDU.getProtocol() & APDU.PROTOCOL_MEDIA_MASK); 
final boolean isContactless = (transportMedia == APDU.PROTOCOL_MEDIA_CONTACTLESS_TYPE_A) || 
         (transportMedia == APDU.PROTOCOL_MEDIA_CONTACTLESS_TYPE_B);
like image 174
vojta Avatar answered Dec 24 '25 10:12

vojta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!