Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to send Pseudo-APDU commands while card is not present?

I am using the javax.smartcardio package for developing smart card related applications. I want to send Pseudo ADPU commands to set my reader's LED / LCD status.

I found that the only method to send APDU commands to reader/card is CardChannel::transmit, but it must be run on card present .

Is it possible to send Pseudo-APDU commands while card is not present in the reader? what about the APDU commands? (Using Java)

like image 230
Bruce Z Avatar asked Sep 28 '22 22:09

Bruce Z


1 Answers

Found a solution from sample of card-emul in SDK for PC/SC in http://www.springcard.com. Here is my code:

import java.util.List;

import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.TerminalFactory;

public class TestPcsc {

    public static void main( String[] args ) throws CardException {

        TerminalFactory tf = TerminalFactory.getDefault();
        List< CardTerminal > terminals = tf.terminals().list();
        CardTerminal cardTerminal = (CardTerminal) terminals.get( 0 );

        byte[] command = { (byte) 0xE0, (byte) 0x00, (byte) 0x00, (byte) 0x29, (byte) 0x01, (byte) 0x00 };
        cardTerminal.connect( "DIRECT" ).transmitControlCommand( CONTROL_CODE(), command );

    }

    public static int CONTROL_CODE() {

        String osName = System.getProperty( "os.name" ).toLowerCase();
        if ( osName.indexOf( "windows" ) > -1 ) {
            /* Value used by both MS' CCID driver and SpringCard's CCID driver */
            return (0x31 << 16 | 3500 << 2);
        }
        else {
            /* Value used by PCSC-Lite */
            return 0x42000000 + 1;
        }

    }

}

I think the points are:

  1. Using DIRECT protocol to get the 'card'
  2. Using Card::transmitControlCommand method with the code got from CONTROL_CODE function (copied from the sample code, not sure what the theory is >_<)
like image 139
Bruce Z Avatar answered Oct 05 '22 22:10

Bruce Z